简体   繁体   English

与Yii合作,有没有办法通过CDbCriteria添加AS进行查询

[英]working with Yii, is there any way to add AS to query via CDbCriteria

so there's the deal: 所以有交易:

I've got a table set up for basic event management. 我已经为基本事件管理设置了表格。 This is done with all of the supporting code in place. 使用所有支持代码即可完成此操作。 I've decided to use the jquery calendar, Full Calendar for display via a JSON feed. 我决定使用jQuery日历,即通过JSON feed显示的完整日历。 This too is in place, but here's the hitch. 这也已经到位,但这是关键。

The data returned by CActiveRecord uses the keys as they are in the database, for example event_id, event_title, etc. When I output the data via Yii's CJSON::encode(), Full Calendar needs keys such as id, title, etc. I'd rather not change the database or my CRUD forms just to accommodate this calendar. CActiveRecord返回的数据使用它们在数据库中的键,例如event_id,event_title等。当我通过Yii的CJSON :: encode()输出数据时,Full Calendar需要诸如id,title等键。宁愿不要仅仅为了适应此日历而更改数据库或CRUD表单。

If I were writing my sql, I would just use AS (ie, SELECT event_id AS id) to facilitate this change, however I can't see a way to do that in Yii. 如果我正在编写sql,我将仅使用AS(即SELECT event_id AS ID)来促进此更改,但是在Yii中看不到做到这一点的方法。 Any suggestions? 有什么建议么? Is there a way to add AS statements to the query in Yii? 有没有办法在Yii中向查询添加AS语句?

Thanks all 谢谢大家

You can set alias in select clause: 您可以在select子句中设置别名:

$criteria->select = array(
    'id as user_id',
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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