php - should generic super class for model be static and singleton? -


status: accepting 1 answer choice. thanks.

shouldn't use static functions , self:: instead of $this-> in here . use class dao super class in of model classes.

the dao class super class of model classes.

should singleton? should use static?

any tips ?

<?php  class dao extends object{     private $con;     //will put in defines includes file. or user wp.     private $dbhost     = "localhost";     private $dbname     = "wpm";     private $dbuser     = "root";     private $dbpass     = "root";      public function __construct() {        if(!$this->con){            $this->con = new pdo("mysql:host=$this->dbhost;dbname=$this->dbname",$this->dbuser,$this->dbpass); //will make generic.         }     }      protected function getcon(){         if(!$this->con){            $this->con = new pdo("mysql:host=$this->dbhost;dbname=$this->dbname",$this->dbuser,$this->dbpass);         }          return $this->con;     }      protected function executequery($query, $fetchtype, $paramarray){         $stmt = $this->getcon()->geprepare($query);         $stmt->execute($paramarray);         $stmt->setfetchmode($fetchtype);//        $stmt->setfetchmode(pdo::fetch_assoc);         $result = $stmt->fetch();         return $result;     }   }  ?> 

dao not model. that's different classes.

dao class should not super class of model. model prototype should super class of model.

"supermodel" should have methods delete(), save(), find() , such. dao should assigned model variable , used way.

as of should supermodel static - depends. frameworks disguise static in loaders, same view, honest static reason despised , disguise have used.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -