bilgikar adlı üyeden alıntı: mesajı görüntüle
Merhaba arkadaşlar, herzaman kullandığım bir listeleme şeklini neden class şekline çevirmiyorum dedim ve bununla ilgili class yazdım.

SONUÇ:

Kullanım:

        $set_list->sql_tb = "messages"; // Sql Tablo adı        
        $set_list->sql_wh= "status = '1'"; // Sql sorgumuz        
        $set_list->sql_tb_att_names = "name,email"; //Sql Tablo attribute(kolonlar)
        $set_list->cl_names = "Gönderen,Email"; //Kolonların Başlığı (Sql Tablo attribute ile aynı sırada)
        
        $set_list->cl_widths = ",200"; // Kolonların genişliği
        
        $set_list->output();
ÇIKTI



KOD KISMI

list.php
class list_records{
    public $id="";
    
    public $tr_header_style= '';
    public $tr_header_class= '';

    public $td_header_style= '';
    public $td_header_class= 'tb_tr_header';

    public $cl_names='';//*
    public $cl_widths='';//*
    
    public $delete_col = true;
    public $update_col = false;
    
    public $extra_col_names = "";
    public $extra_col_links = "";
    public $extra_col_includes = "";
    public $extra_col_widths = "";
    
    public $sql_tb = "";//*
    public $sql_wh;
    
    public $sql_tb_att_names;//*
    public $set_col_arr; //if attribute representative by an array
    
    //tr properties
    public $tr_style= "";
    public $tr_class= "tb_tr_list";    
    //td properties
    public $td_style= "";
    public $td_class= "";        
    
    public $check_box = false;

    public $del_link = "process.php";
    public $update_link = "";
    public $del_ico = "IMG/del.gif";
    public $update_ico = "IMG/edit.png";
    
    public $new_line = FALSE;// if there are new line line will be green
    public $new_line_att = "status";// check new line in a col 1:new line, 0: old
    public $new_line_css_class = "tb_tr_new";

    //form action properties
    public $action = "";
    public $method = "POST";
    public $form_id = "";
    public $enc;    

    //table properties
    public $tb_style = 'font-size: 12px';
    public $tb_class = 'list_tb';
    
    //outer table properties
    public $otb_style = 'font-size: 12px';
    public $otb_class = 'list_tb0';
            
    //adding record button
    public $add_record = false;
    public $add_record_link = "";
    
    public $submit_button_names = "";
    public $submit_button_values = "";
    
    protected function set_submit_buttons()
    {
        if($this->submit_button_values)
            $values = explode(",", $this->submit_button_values);
            $names = explode(",", $this->submit_button_names);
     
        $rst = "";
        
        for($i = 0; $i<count($values); $i++ )
        {
            $rst .= "<input type='button' name=".$names[$i]." value=".$values[$i]."> \n";
        }
        return $rst;
    }
    
    protected function checkbox($v)
    {
        if($this->check_box)
            return "<input type='checkbox' name='row[]' value='".$v."'>";
        else
            return $v;
    }     
}
list_types.php
class list_types extends list_records
{
    function normal_list_header()
    {
        $names = explode(",", $this->cl_names);
        $widths = explode(",", $this->cl_widths);
        $extra_col_names = explode(",", $this->extra_col_names);
        $extra_col_widths = explode(",", $this->extra_col_widths);
        
        $head = "<tr style='".$this->tr_header_style."' class='".$this->tr_header_class."' >\n";
        $head .="<td style='width:30px;' class='".$this->td_header_class."'>&nbsp;</td>";
        
        for($i = 0; $i<count($names); $i++)        
            $head .= '<td style="'.$this->td_header_style.'" class="'.$this->td_header_class.'" width = "'.$widths[$i].'">'.$names[$i].'</td>';
        
        for($i =0 ; $i<count($extra_col_names); $i++)
            $head .= "<td style='width:45px; ".$this->td_header_style."' class='".$this->td_header_class."' width = '".$extra_col_names[$i]."' align='center'>
                        ".$extra_col_names[$i]."</td>";            
        $head .="\n</tr>";
        return $head;
    }
    
    function normal_list_loop()
    {
        global $db;
        $body = "";
        
        $extra_col_names = explode(",", $this->extra_col_names);
        $extra_col_includes = explode(",", $this->extra_col_includes);
        $extra_col_links = explode(",", $this->extra_col_links);        
        
        if(!$db -> get_table($this->sql_tb,$this->sql_wh))
        {
            $cspan=count(explode(",", $this->cl_names))+1;
            $body='<tr>
                    <td align="center" colspan="'.$cspan.'">KAYIT YOK</td>
                </tr>';
        } else {
            $att = explode(",",  $this->sql_tb_att_names);
            
            foreach ($db -> get_table($this->sql_tb,$this->sql_wh) as $r)
            {                    
                $this->cnt++;        
                $body .= "<tr class='tb_tr_list' >\n";
                //******Checkbox setting        
                if($this->check_box) $v = $r["id"]; else $v = $this->cnt;
                $body .= "\t<td class='".$this->td_class."' align='center'>".$this->checkbox($v)."</td>\n";
                for($i=0; $i<count($att); $i++)
                    $body .='   <td style="'.$this->td_style.'" class="'.$this->td_class.'" >'.$r[$att[$i]].'</td>';

               //******EXTRA COLS 
                for($i =0 ; $i<count($extra_col_names); $i++)
                    $body .= "<td  style='".$this->td_style."' class='".$this->td_class."' width = '".$widths[$i]."' align='center'>
                                <a href='".$extra_col_links[$i]."&id=".$r["id"]."'>".$extra_col_includes[$i]."</a>
                              </td>";                
                      
                $body .= "</tr>";
            }
        }
        return $body;
    }
    
    private $cnt = 0;   
    
    public $title = "title";
    public $type = "type";
    public $text = "text";
    public $status = "status";
    public $date = "date";
    
    public $extra = ""; // array by coma
    public $extra_links = ""; // array by coma
    
    function detailed_list() 
    {
        global $db;
        global $general;
        global $status;
        
        $this->substr[$this->title] = 45;
        $this->substr[$this->text] = 201;
        
        $extra = explode(",", $this->extra);
        $extra_links = explode(",", $this->extra_links );       
        if($this->extra)
            for($i=0; $i<count($extra); $i++)
            {
                $extras = '<div class="detailed_line_extra_field" style="text-align: center;" >            
                <a href="'.$extra_links[$i].'">'.$extra[$i].'</a>
                </div>';
            }
        $loop = "";
        //MAIN LIST
        if(!$db -> get_table($this->sql_tb,$this->sql_wh))
        {
            $loop .= '<div style="text-align:center; font-size:14px;">'.$general[2].'</div>';
        } else {
            $att = explode(",",  $this->sql_tb_att_names);
            $cnt = 0;
            foreach ($db -> get_table($this->sql_tb,$this->sql_wh) as $r)
            {
                $cnt++;
                $this->id = $r["id"];
                    $loop .= '
                    <div class = "detailed_line">
                        <div class = "detailed_line_main_part">
                            <div class="detailed_line_top">
                                <span style="float: left; " class="down_detail" id=" '.$cnt.' ">'.$cnt.'#  ('.get_date_format($r["$this->date"],"h:mn - d/m/y ").') '.$this->att_filter($this->type, $r["$this->type"]).'</span>
                                <span style="float: right;" class="warn">'.$status[$r["$this->status"]].'</span>
                                <span style="clear: left; clear: right;"></span>
                            </div>
                            <div class="detailed_line_main">
                                <div style="height: 27px;">
                                    <span style=" font-size: 16px;">'.$this->att_filter($this->title, $r["$this->title"]).'</span>
                                </div>
                                <div style="height: 30px;">
                                    <p style="display: inline; color: #444;">'.$this->att_filter($this->text,$r["$this->text"]).'</p>
                                </div>
                            </div>
                        </div>        
                        <div class="detailed_line_extra_part">
                            '.$this->filter($extras).'
                        </div>
                    </div>
                    ';
            }
        }
        return $loop;
    } 
   
    function output($listing_type = "normal")
    {               
        global $db;
        global $general;
        
        if($this->add_record)
            $add_record = "
                <div style='float:right;'>
                    <a href='".$this->add_record_link."'  style='font-size:10px; '>
                    <img src='IMG/add.png' style='float:left; '>
                    <span style='float:left; line-height:16px; height:16px; cursor:pointer;'>$general[3]</span>                    
                    </a>
                </div>";
        
        echo'
<form action="'.$this->action.'" method="'.$this->method.'" id="'.$this->form_id.'">            
    <table style="'.$this->otb_style.'" class="'.$this->otb_class.'">
        <tr>
            <td align="right" valign="center" style="vertical-align:middle;">
        '.$add_record.'
            </td>
        </tr>
        <tr>
            <td style="height:130px;" valign="top">
                <table style="'.$this->tb_style.'" class="'.$this->tb_class.'" >';
        switch ($listing_type)
        {
            case "":
            case "normal":
                echo $this->normal_list_header();                
                echo $this->normal_list_loop();
                break;
            case "detailed":
                echo $this->detailed_list();
                break;
        }
            echo'</table>
            </td>
        </tr>
        <!--/////////////BUTTOM//////////////-->
        <tr>
            <td>
                <div style="padding:14px 0; text-align:center">
                    '.$this->page_link.'
                    '.$this->page_fast_link.'
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div style="width:55%; float:left; line-height:28px;">
                    Toplam <b>'.$db->row_cnt($this->sql_tb,  $this->sql_wh).'</b> kayıt.
                </div>
                <div style="width:45%; float:left; text-align:right;  line-height:28px;">
                    '. $this->set_submit_buttons().'
                </div>
                <div style="clear:left;">
            </td>
        </tr>
        </table>';        
    }      
}
$set_list = new list_types;
http://speedy.sh/KGJRW/list.rar
Tamamını indir
Not: ayrıca Db classı vardır, sql kodlarıyla ilgili basit ve kullanışlı bir classtır.

GÖRÜŞ VE ÖNERİLERİNİZ:


Classın yazım şekli tek düze mantık
       
function output($listing_type = "normal")
{  
 echo'
<form action="'.$this->action.'" method="'.$this->method.'" id="'.$this->form_id.'">            
    <table style="'.$this->otb_style.'" class="'.$this->otb_class.'">
        <tr>
gibi

Benim sorum şu bu şekilde classlarımı oluşturmaya devammı etmeliyim, bu yol verimli olurmu? yoksa illaki MVC mantığında olan frameworkleri veya phpSmarty gibi sistemlerimi kullanmalyıyım
şıklar:
-Aynen böyle devam, güzel olmuş
-Şöyle yazsaydın daha güzel olurdu ....
-Şöyle bir Tool, enviroment, kit var orada yazsaydın
-Böyle classların zaten olduğu yazılımlar şunlar
-Ne gerek var böyle şeylere bence çok gereksiz.
-diğer


Saygılarımla
Elinize Sağlık Bence Başlamışsınız Devam Ettirin .
Biraz Genişletebilirsiniz Mesela Veritabanından bilgileri tabloya listelerken düzenle , sil Yeni Ekle Gibi Seçeneklerde yaparsanız Kullanışlı Olur Diye Düşünüyorum.