Codeigniter 视图中的IF语句-不显示
好的,我正在尝试验证来自数据库的订阅(这似乎工作正常,因为我在其他地方使用了这个模型)。但是,我试图获取返回的$data并在视图中将其用作IF语句……但是我试图“IF”的DIV没有显示出来。也没有出现任何错误。如果我删除视图中DIV周围的If,内容将出现…我做错了什么 以下是我的控制器中的代码:Codeigniter 视图中的IF语句-不显示,codeigniter,codeigniter-2,Codeigniter,Codeigniter 2,好的,我正在尝试验证来自数据库的订阅(这似乎工作正常,因为我在其他地方使用了这个模型)。但是,我试图获取返回的$data并在视图中将其用作IF语句……但是我试图“IF”的DIV没有显示出来。也没有出现任何错误。如果我删除视图中DIV周围的If,内容将出现…我做错了什么 以下是我的控制器中的代码: // Check subscription and display appropriate content if "freebie" package $subscribe_result = $this
// Check subscription and display appropriate content if "freebie" package
$subscribe_result = $this -> subscribe_model -> upgrade_message($this->session->userdata('user_id')); // session sends user id to model
$data['subscription'] = $subscribe_result;
型号:
// Checks to see what package user has subscribed to
public function upgrade_message($id) //$id is session id pulled from controller
{
$this -> db -> select('subscription'); // select the subscription column
$this -> db -> where('id', $id); //find id in table that matches session id
$query = $this -> db -> get("subscriptions"); // connect to this database
return $query->result_array(); //returns the result of the above
}
最后,我试图输出视图中的IF语句:
<? if($subscription == 'Freebie') : ?>
<div>some "freebie" content</div>
<? endif ?>
一些“免费”的内容
您可以使用
if($subscription[0]['subscription'] == 'Freebie')
而不是
if($subscription == 'Freebie')
有关的详细信息。您可以使用
if($subscription[0]['subscription'] == 'Freebie')
而不是
if($subscription == 'Freebie')
有关的详细信息。如果在视图中执行此操作,您将看到变量包含的内容。我敢打赌这不是免费的返回一个数组,您正在检查
Freebie
,这就是问题所在。下面是变量转储:array(1){[0]=>array(1){[“subscription”]=>string(7)“Freebie”}
如果您在视图中执行此操作,您将看到变量包含什么。我敢打赌这不是免费的返回一个数组,您正在检查Freebie
,这就是问题所在。下面是变量转储:array(1){[0]=>array(1){[“subscription”]=>string(7)“Freebie”}
工作!!我发誓这是我第一次看到的-啊!。今天已经写了13个小时的代码,也许是时候小睡一下了。哈哈:)谢赫,干杯!在调用$subscription[0]
之前,您可能需要先检查$subscription
是否有值,否则如果没有值,将导致错误…;)作品我发誓这是我第一次看到的-啊!。今天已经写了13个小时的代码,也许是时候小睡一下了。哈哈:)谢赫,干杯!在调用$subscription[0]
之前,您可能需要先检查$subscription
是否有值,否则如果没有值,将导致错误…;)