상태 : 단 하나의 대답 선택 만 받음. 고마워.모델의 일반 수퍼 클래스는 정적이어야하며 싱글 톤이어야합니까?
여기에 $this->
대신 self::
을 사용하지 않아야합니다. 내 모든 모델 수업에서이 클래스 Dao를 super class
으로 사용할 것입니다.
DAO를 클래스는 model classes.
그것이 싱글이어야한다 모두의 슈퍼 클래스가 될 것인가? 정적으로 사용해야합니까?
팁이 있습니까?
<?php
class Dao extends Object{
private $con;
//will put this in defines includes file. Or user from 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 it 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;
}
}
?>
'delete() save()'등등은'php'에 대해서 너무 일반적입니다. 각 엔티티에 대한 질의를 작성해야합니다. 예 : findUserByEmail() findJobById(). 둘째로'슈퍼 모델'에서'싱글 톤'과'통계학'을 사용해야 하는가? 'dao naming' 무시. –
findUserByEmail()은 수퍼 모델 메소드가 아닙니다. find() 및 save() - are입니다. 슈퍼 모델은 싱글 톤이어야한다. 아니면 모델이 싱글 톤이어야하는지에 대한 질문인데, –
인데, findUserByEmail()과 find()를위한 예제 코드를 줄 수 있는가? 'singleton'과'static' 문제는 1 - 모범 사례를 아는 것이 었습니다. 2- 스레드 안전성에 대한'$ connection '문제가있었습니다. –