Php 查询Yii CDBC标准

Php 查询Yii CDBC标准,php,yii,Php,Yii,我需要使用CDbCriteria创建一个查询: select t_devices.* from t_departmens, t_branches, t_cabinets, t_employees, t_devices where t_branches.id_organization = 1 and t_departmens.id_branch = t_branches.id_branch and t_cabinets.id_department = t_departmens.id_depart

我需要使用CDbCriteria创建一个查询:

select t_devices.* 
from t_departmens, t_branches, t_cabinets, t_employees, t_devices
where t_branches.id_organization = 1
and t_departmens.id_branch = t_branches.id_branch
and t_cabinets.id_department = t_departmens.id_department
and t_employees.id_cabinet = t_cabinets.id_cabinet
and t_devices.id_employee = t_employees.id_employee
试试这个

$criteria = new CDbCriteria;
$criteria->select('t_devices.*'); 
$criteria->from('t_departmens, t_branches, t_cabinets, t_employees, t_devices');
$criteria->condition('t_branches.id_organization = 1
and t_departmens.id_branch = t_branches.id_branch
and t_cabinets.id_department = t_departmens.id_department
and t_employees.id_cabinet = t_cabinets.id_cabinet
and t_devices.id_employee = t_employees.id_employee
');

建议的方法是在模型文件中使用活动记录AR关系

阅读:

应收账款关系将使用Gii自动生成


阅读:

你试过什么?这是对CDBC标准的简单重写。考虑使用关系!尝试使用联接,它们很好而且很有用。然后尝试建立一些关系,它们也很好,然后使用CDBC标准,这也很好。