简体   繁体   中英

Query to Yii CDbCriteria

I need to create a query using 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

try this

$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
');

The recommended way is to make use of Active Record (AR) relation in your model file.

Read: Yii's active record guide

AR relations will be generated automatically using Gii

Read: Yii's Gii Guide

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM