how to use isset inside addCondition in yii criter

2019-08-23 13:35发布

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

标签: php yii
3条回答
疯言疯语
2楼-- · 2019-08-23 13:54

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');
查看更多
贪生不怕死
3楼-- · 2019-08-23 14:04

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.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-08-23 14:13

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

查看更多
登录 后发表回答