脚本宝典收集整理的这篇文章主要介绍了php – 如何在Yii $条件中使用DATE_ADD?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
// Declare $datetime_limIT public datetime_limit;
Controller.PHP这样
// datetime_limit should be the actual datetime + 5 days $criteria->select="DATE_ADD(Now(),INTERVAL 5 DAY) AS datetime_limit";
错误信息:
Active record "Users" is trying to select an invalid column "DATE_ADD(Now()". Note,the column must exist in the table or be an exPression with alias.
编辑1:
我想使用关系表(多对多)过滤查找条件.
所以datetime_limit不能在关系events.datetime中.
我怎样才能做到这一点?
$criteria->select=array("DATE_ADD(Now(),INTERVAL 5 DAY) AS datetime_limit"); $criteria->with=array('events'); $criteria->having='datetime_limit!=`events`.`datetime`'; $models=Users::model()->findAll($criteria);
CActiveFinder::getColumnSelect
中引发.
当CDbCriteria :: $select是一个字符串时,它被视为逗号分隔列的简单列表.您的表达式被解释为两个不同的列.你可以通过自己设置选择来解决这个问题 – 在这种情况下,逗号分割不是完成1:
$criteria = new CDbCriteria(); $criteria->select = array("DATE_ADD(Now(),INTERVAL 5 DAY) AS datetime_limit"); $models = Users::model()->findAll($criteria);
请注意,如果您编写的别名与公共模型属性或数据库字段不对应,则会检索它,但会被忽略 – 由于某种原因,Yii不会为此抛出异常.
以上是脚本宝典为你收集整理的php – 如何在Yii $条件中使用DATE_ADD?全部内容,希望文章能够帮你解决php – 如何在Yii $条件中使用DATE_ADD?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。