检查True返回的表单codeigniter模型

时间:2016-07-14 09:56:03

标签: php codeigniter

我想要一种简单但正确的方法来检查是否从codeigniter模型返回了true或false。

SO

如果我的模型返回了true,我可以在控制器中执行此操作吗?

if($variable = $this->ci_model->model_method($user_id)){
 // true, was returned do something
}

或者我必须专门测试是否返回了true,我该怎么做?

1 个答案:

答案 0 :(得分:2)

执行此操作:

 $variable = $this->ci_model->model_method($user_id);
 if(!empty($variable))
 {
   return true
 }
  else 
 {
  return false;
 }

或者你可以这样:

if($this->ci_model->model_method($user_id))
 {
   return true
 }
  else 
 {
  return false;
 }
相关问题