【发布时间】:2012-11-08 06:14:56
【问题描述】:
简单的问题,但我不知道为什么它不能正确打印或按预期工作。我在模型中有这个(有效,因为当我 print_r($result) 它显示数据时:
function get_latest_entries()
{
$query = $this->db->get('property');
return $query->result_array();
}
对于控制器:
public function index()
{
$resultSet['properties'] = $this->propertymodel->get_latest_entries();
$this->load->view('home', $resultSet);
}
在视图中我想遍历数组(表有描述、城市、地址列):
<?php
foreach($resultSet as $item)
{
echo $item->city;
echo $item->description;
}
?>
我在主页上得到两条记录,显示结果如上:
严重性:通知 消息:未定义的变量:resultSet 文件名:views/home.php 行号:16
还有
严重性:警告 消息:为 foreach() 提供的参数无效 文件名:views/home.php 行号:16
【问题讨论】:
-
使用 $properties 而不是 $resultSet
-
把它作为答案@ShayanHusaini,这样我就可以将它标记为一个:)
标签: codeigniter