Cakephp 3模型函数的最佳编码实践
我有一个current_day_users表和users表。在从current_day_用户提取数据时,以下两者之间的编码实践更好: 1.UsersTable.php代码Cakephp 3模型函数的最佳编码实践,php,oop,cakephp,cakephp-3.0,cakephp-3.1,Php,Oop,Cakephp,Cakephp 3.0,Cakephp 3.1,我有一个current_day_users表和users表。在从current_day_用户提取数据时,以下两者之间的编码实践更好: 1.UsersTable.php代码 $this->CurrentDayUsers->find()->where(['user_id'=>$userId,'created'=>$dateToday])->first(); public function findUser($userId,$date){ retur
$this->CurrentDayUsers->find()->where(['user_id'=>$userId,'created'=>$dateToday])->first();
public function findUser($userId,$date){
return $this->find()->where(['user_id'=>$userId,'created'=>$date])->first();
}
$this->CurrentDayUsers->find()->where(['user_id'=>$userId,'created'=>$dateToday])->first();
public function findUser($userId,$date){
return $this->find()->where(['user_id'=>$userId,'created'=>$date])->first();
}
$this->CurrentDayUsers->findUser($userId,$dateToday) $this->CurrentDayUsers->find()->where(['user_id'=>$userId,'created'=>$dateToday])->first();
public function findUser($userId,$date){
return $this->find()->where(['user_id'=>$userId,'created'=>$date])->first();
}
如果您已经有CurrentDayUsers表,我建议您采用第二种方法:
public function findUser($userId,$date){
return $this->find()->where(['user_id'=>$userId,'created'=>$date])->first();
}
这是一个简洁的代码,而不是在Users表中使用查询生成器