how to use isset inside addCondition in yii criteria

ぐ巨炮叔叔 提交于 2019-12-25 09:59:09

问题


Hi I've been trying to check if a field is existing using isset inside addCondition like this

$criteria->addCondition('isset(status_id)');

but no luck. Can anyone suggest the right syntax for this? thanks


回答1:


For checking a variable, you can use isset(). But what you are trying to do is not the correct way. The addCondition method is not supposed to execute PHP functions. Check the documentation

But If you want to check the value in status_id, tou can do like this -

$criteria->addCondition('status_id IS NOT NULL');



回答2:


check that your variable is set and it is in the correct form that you want, then add it in your condition.like:

if(isset($var) && preg_match($yourPattern , $var))
    $criteria->addCondition('status_id =' . $var );

if you use "compare" , it doesn't matter that it is set or not.




回答3:


try this: if(isset(status_id)) {$criteria->addCondition('status_id');}



来源:https://stackoverflow.com/questions/18954600/how-to-use-isset-inside-addcondition-in-yii-criteria

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!