Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 检查真正返回的表单codeigniter模型_Php_Codeigniter - Fatal编程技术网

Php 检查真正返回的表单codeigniter模型

Php 检查真正返回的表单codeigniter模型,php,codeigniter,Php,Codeigniter,我想要一个简单但正确的方法来检查codeigniter模型是否返回了true或false 所以 如果我的模型返回true,我可以在控制器中执行此操作吗 if($variable = $this->ci_model->model_method($user_id)){ // true, was returned do something } 或者我必须专门测试是否返回了true,以及如何才能这样做?这样做: $variable = $this->ci_model->mo

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

所以

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

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

或者我必须专门测试是否返回了true,以及如何才能这样做?

这样做:

 $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;
 }
或者您可以这样做:

 $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;
 }

这样做:

 $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;
 }
或者您可以这样做:

 $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;
 }

如果返回值为真,则无需执行特殊操作。你也可以使用
if($this->ci\u model->model\u method($user\u id))
所以如果我想检查false,我可以这样做
if(!$this->ci\u model->model\u method($user\u id))
正确!!!如果真的返回,则无需执行特殊操作。你也可以使用
if($this->ci\u model->model\u method($user\u id))
所以如果我想检查false,我可以这样做
if(!$this->ci\u model->model\u method($user\u id))
正确!!!着手