I’m developing Yii powered application. I want to convert this SQL:
SELECT m.sendDate, m.status, c.name, c.email, mt.name, mt.subject, CONCAT( op.firstName, ' ', op.lastName ) operator
FROM `mail` m, client c, mailTemplate mt, operator op
WHERE m.customerID = c.id
AND m.operatorID = op.id
AND m.templateID = mt.id
AND c.name LIKE '%L%'
AND c.email LIKE '%@gmail.com%'
AND m.sendDate < '2012-07-31'
AND m.sendDate > '2012-06-30'
into CDBcriteria but don’t know how.
First, you must to create 4 models: Mail, Client, MailTemplate, Operator.
In Mail model define relations:
And…
Well, now we can find items:
UPDATE for second question:
Define method search in your Mail model:
and in gridview, columns you must use relations
$data is a one item of Mail model with relations.