Php 无法加入codeigniter
我的表格结构Php 无法加入codeigniter,php,mysql,sql,codeigniter,Php,Mysql,Sql,Codeigniter,我的表格结构“页面”: id int(11) title varchar(100) slug varchar(100) order varchar(100) body text parent_id int(11) (0/1) 我正在尝试将一个表连接到它本身,以便可以获得具有父项的页面(即parent\u id和1)。我在我的页面模型中使用了这个方法,它扩展了myu模型,但它不起作用 public function get_with_parent ($id = NULL, $single =
“页面”
:
id int(11)
title varchar(100)
slug varchar(100)
order varchar(100)
body text
parent_id int(11) (0/1)
我正在尝试将一个表连接到它本身,以便可以获得具有父项的页面(即parent\u id
和1
)。我在我的页面模型中使用了这个方法,它扩展了myu模型
,但它不起作用
public function get_with_parent ($id = NULL, $single = FALSE)
{
$this->db->select('pages.*, p.slug as parent_slug, p.title as parent_title');
$this->db->join('pages as p', 'pages.parent_id=p.id', 'left');
return parent::get($id, $single);
}
MY_模型:
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) {
$method = "row";
} else {
$method = "result";
}
if(!count($this->db->ar_order)) {
$this->db->order_by($this->_order_by);
}
return $this->db->get($this->_tablename)->$method();
}
您在查询中遗漏了
public function get_with_parent ($id = NULL, $single = FALSE)
{
$result = $this->db->select('pages.*, p.slug as parent_slug, p.title as parent_title')
->from('pages');//here you need to put this code
->join('pages as p', 'pages.parent_id=p.id', 'left');
return parent::get($id, $single);
}
带有父函数的公共函数get\u($id=NULL,$sengle=FALSE) { $this->db->select('pages.*,p.slug作为父级\u slug,p.title作为父级\u title') ->其中(“pages.language”,$this->uri->segment(1)) ->join('pagesas p','pages.parent_id=p.id','left') 返回父项::get($id,$sengle) }