Extending A PHP Class - Help Understanding -


i having little trouble understanding how class extends another. have model class.

class model{     public $db;      public function __construct(){         $this->db = $globals['db'];      }      public function _sel($table, $where="", $order_by="", $limit="", $group_by="",$database = null){                     if($database === null) {  $database = $this->db; }         // yada yada yada         $results = $database->select($sql);     } 

and have pagination class extend it:

    class pagination extends model {          public $limit;         public $page;         public $criteria;         private $_totalrecords;         private $_totalpages;             public function __construct(){                // initialize             $arguments = func_get_args();             if(!empty($arguments)){                 foreach($arguments[0] $key => $property){                     if(property_exists($this, $key)){                         $this->{$key} = $property;                     }                 }             }          }          public function getpaginationpage(){           // yada yada yada           // next line causes issue           $records = $this->_sel($query['table'],$query['where'],$query['order_by'],$start." , ".$end,$query['group_by'],$query['database']); 

to keep post short tried include necessary sections of code. issue having when execute query in extended class failing because $this->db has no value. since set in constructor seems me need call again $xx = new model() since it's extension of class should exist confused why not have value. admittedly self taught , starting classes. understanding of them wrong or there need make sure "extends"?

also how calling extended class:

$this->model->pagination = new pagination(array(             'limit'     =>  10,             'page'      =>  1,             'criteria'  => array('projects','status_id > 0','name asc',''),                  )); 

you have overwritten model constructor in pagination class. call parent's constructor child's constructor retain both:

class pagination extends model {     ...      public function __construct() {          parent::__construct();         ... 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -