I Watched系列在tutlus的codeigniter中增加了一个cms。
页:
public function get_no_parents() {
// Fetch pages without parents
$this->db->select('id', 'title');
$this->db->where('parent_id', 0);
$pages = parent::get();
// Return key => value pair array
$array = array(
0 => 'No parent');
if(count($pages)) {
foreach($pages as $page) {
$array[$page->id] = $page->title;
}
}
return $array;
}
MY_Model.php
public function get($id = NULL, $single = FALSE){
if ($id != NULL) {
$filter = $this->_primary_filter;
$id = $filter($id);
$this->db->where($this->_primary_key, $id);
$method = 'row';
}
elseif($single == TRUE) {
$method = 'row';
}
else {
$method = 'result';
}
if (!count($this->db->ar_orderby)) {
$this->db->order_by($this->_order_by);
}
return $this->db->get($this->_table_name)->$method();
}
}
当我获得数据时,结果返回:0 => '没有父母',正确的是:0 =>没有父母,1 =>主页,2 =>约。
数据库:
id | title | parent_id
1 | Homepage | 0
2 | About | 0