【发布时间】:2015-10-19 15:01:16
【问题描述】:
过去 2 小时我一直在努力找出为什么会出现此错误,但我仍然卡住了!我已经检查了这里的答案,但仍然没有。
在检查了类似的帖子后,我似乎找不到解决方案
我们将不胜感激
错误信息:
遇到了 PHP 错误
严重性:通知
消息:未定义变量:升级
文件名:views/Test.php
行号:207
型号:
<?php
if(!defined('BASEPATH')) exit('Hacking Attempt: Get out of the system ..!');
class M_live extends CI_Model {
function M_live(){
parent::Model();
function getUpgrades(){
$this->db->select("*");
$this->db->from('client_trust_versions')
$query = $this->db->get();
return $query->result_array();
}
}
}
?>
控制器:
<?php
if(!defined('BASEPATH')) exit('Hacking Attempt: Get out of the system ..!');
class C_Live extends CI_Controller
{
function C_Live(){
parent::__construct();
$this->load->model('M_live');
}
public function index(){
$query = $this->M_live->getUpgrades();
$data['UPGRADES'] = null;
if($query){
$data['UPGRADES'] = $query;
}
$this->load->view('Test', $data);
}
}
?>
查看:
<table>
<tr>
<th>ID</th>
<th>Client Name</th>
<th>App Server</th>
<th>Instance Name</th>
<th>BankStaff Server</th>
<th>SQL Server</th>
<th>Instance</th>
<th>Health Roster Version</th>
<th>Employee Online Version</th>
<th>Roster Perform</th>
<th>BankStaff Version</th>
<th>SafeCare Version</th>
<th>E-Expenses</th>
</tr>
<?php foreach((array)$UPGRADES as $upgrades){?>
<tr><td><?php=$upgrade->ID;?></td>
<td><?php=$upgrade->Client_Name;?></td>
<td><?php=$upgrade->App_Server;?></td>
<?php }?>
【问题讨论】:
-
好吧,我猜查询不会返回结果。要测试用
$data['UPGRADES'] = array();替换$data['UPGRADES'] = null;- 它应该可以工作 -
如果你看一下变量名,你在
foreach-语句中使用$upgrades,但在其中使用$upgrade。 -
更改为升级并将 null 换成数组,但仍然出现错误...
-
您忘记附上模型的构造方法。此外,模型代码属于 CI 的旧(小于 2.x.x)版本。应该是这样吗?您的应用的 CI 版本是多少?
标签: php codeigniter model-view-controller foreach undefined