【发布时间】:2014-11-20 16:29:19
【问题描述】:
我想从数据库中获取没有 parent_id 的页面的记录,或者我们可以说没有父页面的页面..
页面模型 ......................................
public function get_no_parents() {
// fecth pages wihtout parents
$this->db->select ( 'id','title' );
$this->db->where ( 'parent_id', 0 );
$pages = parent::get ();
// if there are pages then return key as page->id and value $page->title
$array = array (
0 => 'no parent'
);
if(is_array($pages)){
foreach ($pages as $page){
$array[$page->id]=$page->title;
$return $array;
}
}
}
.....页面控制器
$this->data['pages_no_parents']=$this->Page_model->get_no_parents();
var_dump($this->data['pages_no_parents']);
.... 转储为空我有两个错误
1- 未定义属性:stdClass::$title
2- 为 foreach() 提供的参数无效
有人可以帮助我吗?
【问题讨论】:
-
问题依然存在
-
仍然存在一个问题,但您还有另一个问题。
parent::get();返回什么? -
它将从父类返回数据库中的页面
-
嗯,它应该,但它不返回一个数组...
var_dump它 -
没有一个错误被修复,未定义的属性:stdClass::$title 我仍然收到错误
标签: php mysql codeigniter