class Retailjob extends CFormModel {
public function getReatilProducts() {
$condition=false;
$user = Yii::app()->db->createCommand()
->select('tbl_retailjob.retailjobmaster_id, tbl_retailjob.joborderflag, tbl_retailjoborder.retailjob_id, tbl_retailjoborder.retailjobsub_id, tbl_retailjoborder.filename,tbl_retailpostpressjoborder.retailpostpressjo_id,tbl_retailpostpressjoborder.retailjobsub_id,tbl_retailpostpressjoborder.retailpostpresssub_id')
->from('tbl_retailjob')
->join('tbl_retailjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailjoborder.retailjobmaster_id')
->join('tbl_retailpostpressjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailpostpressjoborder.retailjobmaster_id')
->where('tbl_retailjob.retailjobmaster_id=:id', array(':id' => 7))
->queryAll();
return $user;
}
}
これは私のモデル ファイルです。達成したいのは、$condition が true の場合、where 条件を回避する必要があり、false の場合は含める必要があることです。
このように達成できますか
public function getReatilProducts() {
$condition=true;
$user = Yii::app()->db->createCommand()
->select('tbl_retailjob.retailjobmaster_id, tbl_retailjob.joborderflag, tbl_retailjoborder.retailjob_id, tbl_retailjoborder.retailjobsub_id, tbl_retailjoborder.filename,tbl_retailpostpressjoborder.retailpostpressjo_id,tbl_retailpostpressjoborder.retailjobsub_id,tbl_retailpostpressjoborder.retailpostpresssub_id')
->from('tbl_retailjob')
->join('tbl_retailjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailjoborder.retailjobmaster_id')
->join('tbl_retailpostpressjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailpostpressjoborder.retailjobmaster_id')
if ($condition !=true) {
->where('tbl_retailjob.retailjobmaster_id=:id', array(':id' => 7))
}
->queryAll();
return $user;
}
}