Arkadaşlar öncelikle iyi bayramlar. OOP yapısının gerektirdiği tüm bilgilere aslında sahibim. Interface,abstract,inheritance gibi tüm konuları biliyorum fakat kod yazarken oop yapısında ihtiyacı görmek konusunda kafam karışabiliyor.
Bildiğiniz OOP yapısı kullanılarak yapılmış ve internette yayınlanan örnek projeler varsa benimle paylaşabilirmisiniz? İncelemek isterim.
Not: Sadece php diliyle yazılmış olmasına gerek yok. Amaç projede nasıl kullanıldıklarını incelemek. c# diliyle de yazılmış olabilir.
OOP PHP ile yapılmış örnek projelere ihtiyacım var
6
●1.428
- 28-06-2017, 14:40:28Symfony, Laravel gibi projeleri incelemenizi tavsiye ederim.MaxidaTa adlı üyeden alıntı: mesajı görüntüle
- 30-06-2017, 23:20:41Laravel ,symfony gibi frameworklerden ziyade düz php ile yazılmış olan uygulamaları incelemenizi öneririm.
https://github.com/dtoyee/OOP-Blog - 02-07-2017, 13:45:08Güzel bir örnektir,
https://www.codexworld.com/php-oop-c...tension-mysql/
MaxidaTa adlı üyeden alıntı: mesajı görüntüle - 02-07-2017, 23:10:35Size yönetim paneli altyapım için hazırlamış olduğum bir tablo oluşturma sınıfını vereyim ;
Editör'de kodlar daha düzenli buraya yapıştırdığımda bozuldu birazcık
@MaxidaTa;
class Table { /** * Tabloda gösterilecek olan alanları belirlemek için kullanılır. * Örnek: * array * ( * 'id' => 'ID', * 'name' => 'Adı ve Soyadı', * ); * * @param string array * @return array */ public $_columns = array(); /** * Sıralama uygulanacak olan sütünları belirtmek için kullanılır * * @access public * @return array */ public $_sortable = array(); /** * Sayfalama kullanılacak mı ? * true aktif hale false değeri ise pasif hale getirir. * * @param string $boolean * @return boolean */ public $_pagination = array(); /** * Default Sıralama */ public $order_by = 'ORDER BY id DESC'; /** * Kurucu Method.. * Şu an her hangi bir işlevi yok :) */ public function __construct() { } /** * Sayfalama sistemini hazırlar. * Gönderilen Parametreler * @param integer $count * @param integer $limit * @access public */ public function set_pagination( $count = 0 , $limit = 10 ) { $this->paginate = ''; $this->limit = abs(isset( $_GET['limit'] ) && intval($_GET['limit']) > 0 ? $_GET['limit'] : $limit); if( $this->limit > 200 ) { $this->limit = $limit; } $this->total = $count; $this->pcount = ceil( $count / $this->limit ); $this->page = intval( $_GET['page'] ) > 0 ? $_GET['page'] : 1; if( $this->page > $this->pcount ) { $this->page = 1; } $this->offset = ( $this->page * $this->limit ) - $this->limit; if( $this->limit < $this->total ) { $output = '<div class="pagination">'; if( $this->page <= 1 ) { $output.= '<a href="" class="btn btn-default btn-xs" disabled="">İlk</a>'; } else { $output.= '<a href="'.add_query_arg('page' , 1).'" class="btn btn-default btn-xs">İlk</a>'; } if( $this->page > 1 ) { $output.= '<a href="'.add_query_arg('page' , $this->page - 1).'" class="btn btn-default btn-xs">Önceki</a>'; } else { $output.= '<a href="" class="btn btn-default btn-xs" disabled="">Önceki</a>'; } for( $i = $this->page - 5; $i < $this->page + 6 ; $i++ ) { if( $i > 0 && $i <= $this->pcount ) { $output.= ' <a href="'.add_query_arg('page' , $i).'" class="btn btn-'.($i == $this->page ? 'pink' : 'default').' btn-xs">'.$i.'</a> '; } } if( $this->page >= 1 && $this->page < $this->pcount ) { $output.= '<a href="'.add_query_arg('page' , $this->page + 1).'" class="btn btn-default btn-xs">Sonraki</a>'; } else { $output.= '<a href="" class="btn btn-default btn-xs" disabled="">Sonraki</a>'; } if( $this->page < $this->pcount ) { $output.= '<a href="'.add_query_arg('page' , $this->pcount).'" class="btn btn-default btn-xs">Son</a>'; } else { $output.= '<a href="" class="btn btn-default btn-xs" disabled="">Son</a>'; } $query_vars = ''; unset( $_GET['limit'] ); foreach( $_GET as $k => $v ) { $query_vars.= '<input type="hidden" name="'.$k.'" value="'.$v.'" />'; } $output.= ' <div style="float: right"> <form action="" method="get" style="display: inline-block"> '.$query_vars.' Limit : <input class="limit-input" onchange="$(this).parent().submit();" style="height: 24px; border: 1px solid #ccc; padding: 3px; width: 50px;" type="text" name="limit" value="'.$this->limit.'"/> </form> </div>'; $output.= '</div>'; $this->paginate = $output; } } public function sort_by() { $sort_by = $this->sort_by; $column = in_array( $_GET['column'] , $sort_by ) ? $_GET['column'] : ''; $type = strtolower( $_GET['order'] ) == 'asc' ? 'ASC' : 'DESC'; if( $column ) { return "ORDER BY {$column} {$type}"; } else { return $this->order_by; } } public function display() { $column_length = count( $this->columns ); ?> <?php if( $this->show_search == true ) { ?> <form class="form-inline" method="get"> <input type="hidden" name="do" value="<?php echo $_GET['do']; ?>"/> <div class="form-group"> <input search type="search" name="search" value="<?php echo $_GET['search']; ?>" class="form-control" placeholder="Aranacak Kelime"> </div> <button type="submit" class="btn btn-sm btn-primary btn-shadow"><i class="fa fa-search"></i> Arama</button> <button type="reset" onclick="location.href='?do=<?php echo $_GET['do']; ?>';" class="btn btn-sm btn-danger btn-shadow"><i class="fa fa-times"></i> Sıfırla</button> </form> <br/> <?php } ?> <?php echo $this->paginate; ?> <form action="" class="form-inline" method="post"> <table class="ed-table table table-hover"> <thead> <?php $output = ''; if( method_exists( $this , 'set_sortable') ) { $this->sortable = $this->set_sortable(); } foreach( $this->columns as $key => $val ) { if( $key == 'cb' ) { $val = '<input class="cb" type="checkbox" value=""/>'; } if( count($this->sort_by) > 0 && in_array( $key , $this->sort_by ) ) { $order = ( $_GET['order'] == 'ASC' ? 'DESC' : 'ASC' ); $url = add_query_arg(array('column' => $key , 'order' => $order)); $img = ( $_GET['order'] == 'ASC' ? '<i class="fa fa-angle-down"></i>' : '<span class="fa fa-angle-up"></span>' ); $output.= '<th class="column-'.$key.'"><a href="'.$url.'">'.$val.' '.($_GET['column'] == $key ? $img : '').'</a></th>'; } else { $output.= '<th class="column-'.$key.'">'.$val.'</th>'; } // $output.= '<th class="column-'.$key.'">'.$val.'</th>' . "\n"; } echo $output; ?> </thead> <tbody class="ed-body tbody"> <?php $output = ''; if( count( $this->items ) > 0 ) { for( $i = 0; $i < count( $this->items ); $i++ ) { $items = is_object( $this->items[$i] ) ? object_to_array($this->items[$i]) : $this->items[$i]; $output.= '<tr>'."\n"; foreach( $this->columns as $key => $val ) { $output.= '<td>'.$items[$key].'</td>' . "\n"; } $output.= '</tr>'."\n"; } } else { $output.= '<tr><td colspan="'.$column_length.'">Listelenecek veri bulunamadı.</td></tr>'; } echo $output; ?> </tbody> </table> <?php if( $this->paginate ) { ?> <br /> <?php echo $this->paginate; ?> <?php } if( is_array( $this->actions ) && count( $this->actions ) > 0 ) { ?> <br> <div class="action-table"> <div class="form-group" style="display: inline-block"> <select style="width: 150px" name="action" class="form-control"> <option value="">Seçilenleri..</option> <?php if( $this->excell ) { ?> <option value="excell">Excell Çıktısı Al</option> <?php } ?> <?php foreach( $this->actions as $key => $val ): ?> <option value="<?php echo $key; ?>"><?php echo $val; ?></option> <?php endforeach; ?> </select> </div> <button type="submit" style="position: relative; top: 0px; margin-left:5px; " onclick="return confirm('Emin misiniz?');" class="btn btn-sm btn-shadow btn-primary"><i class="fa fa-paper-plane"></i> Uygula</button> </div> <?php } ?> <?php form_token('admin-token'); ?> </form> <?php } }Kullanımı ;
class List_Item Extends Table { public function __construct() { $this->show_search = true; } public function prepare() { $this->columns = array ( 'cb' => '', 'name' => 'Kullanıcı Adı', 'email' => 'E-mail', 'type' => 'Üyelik Türü', 'status' => 'Durum', 'created_at'=> 'Tarih', 'id act1' => '', 'id act2' => '', ); $this->sort_by = array('id' , 'name' , 'email' , 'type' , 'status' , 'created_at'); $this->actions = array ( 'active' => 'AKTİF', 'passive' => 'PASİF', 'delete' => 'SİL', ); $this->set_pagination( Users::total("SELECT COUNT(id) FROM users") , $limit = 50 ); $query = Users::sql("SELECT * FROM users ".$this->sort_by()." LIMIT {$this->offset} , {$this->limit}"); foreach( $query as $row ) { $this->items[] = array ( 'cb' => '<input type="checkbox" name="id[]" value="'.$row->id.'"/>', 'name' => '<a href="?do=users&q=action&id='.$row->id.'" class="tlink"><img style="border-radius: 50%; margin-right: 5px" src="'.get_gravatar( $row->email , 20).'" alt="">'.$row->name.'</a>', 'email' => '<a href="index.php?do=send_mail&email='.$row->email.'" class="send-email"><i class="fa fa-envelope"></i>'.$row->email.'</a>', 'type' => get_label('user.auth.'.$row->type), 'status' => get_label('global.status.'.$row->status , 'users' , $row->id), 'created_at' => show_date( $row->created_at ), 'id act1' => '<a href="?do=users&q=action&id='.$row->id.'" title="Düzenle"><i class="fa fa-pencil"></i></a>', 'id act2' => '<a class="delete" href="?do=users&q=delete&id='.$row->id.'" title="Kalıcı olarak sil"><i class="fa fa-trash"></i></a>', ); } } }Örnek Çıktı ;
Direk çalışmayacaktır kendi altyapıma ait bir sınıfı paylaştım yönetim , arayüz her yerde kullanırım daha çok fazla geliştirmedim ancak geliştirmeye müsait ve 20 tane listeleme sayfam olduğunda tek yerden işlem yapıyorum bir güncelleme yapacağım zaman pratiklik ve temiz kod yazımını sağlıyor.
- 03-06-2020, 01:40:46Bu uygulamanın databasesini bulamadım. Görüntüleyebiliyor muyuz ?BoraBozdogan adlı üyeden alıntı: mesajı görüntüle
