如何在YIi中将自定义查询转换为CDbCriteria。我试过这样,也许不完整:
$criteria=new CDbCriteria;
$criteria->select='t.kode, t.status, p.berlaku_punish AS p_berlakupunish,p.nilai AS p_nilai';
$criteria->join = 'LEFT JOIN punish p ON (p.id_status = t.id)';
myquery : `$sql="SELECT status.id, status.kode, status.status, m1.berlaku_punish, m1.nilai
FROM STATUS LEFT JOIN punish m1 ON status.id = m1.id_status
AND m1.id = ( SELECT MAX( m2.id ) FROM punish m2 WHERE m2.id_status = status.id)";`
如何在myquery中将 AND 插入我的自定义不完整的CDbCriteria? 索里,关于我的英语。
答案 0 :(得分:1)
您可以像这样使用addCondition
:
$criteria->addCondition("function_id =ur_value");
$criteria->addCondition("legal_id =ur_value");
它将定义function_id=ur_value
和legal_id=ur_value
或者你可以使用这样的条件:
$criteria->condition="function_id=ur_value AND legal_id=ur_value";