直升机。我正在尝试制作一个物品分页。我有3个功能,第一个显示类别,第二个显示sucategory。第三个显示项目是冷get_books_by_subcategory。第3个函数得到一个segment-> url(3)argumnet,我想在同一个函数中进行分页。但我不能这样做。
这是控制器中的功能代码:
function get_category()
{
$query = $this->Kategorie_model->get_category();
$this->response['podkategorie'] = '';
$this->response['kategorie'] = '';
$podkategorie = '';
if($query->num_rows() > 0)
{
foreach($query->result() as $item)
{
$podkategorie = $this->get_sub_category($item->CAT_ID);
$this->response['kategorie'] .= $this->load->view('Ksiegarnia/left', array('kategorie' =>$item, 'podkategorie'=>$podkategorie), true);
}
}
$data = $this->response['kategorie'];
return $data;
}
function get_sub_category($id)
{
$this->response['wynik'] = '';
$query = $this->Kategorie_model->get_sub_category($id);
if($query->num_rows() > 0)
{
foreach($query->result() as $row)
{
$link = site_url('ksiegarnia/get_books_by_subcategory/'.$row->SUBC_ID);
$this->response['wynik'] .= '<div class="subcat_name"><a href = "'.$link.'">'.$row->SUBC_Name.'</a></div>';
}
}
else
{
$this->response['wynik'] = '<H1>BRAK DANYCH </H1>';
}
return $this->response['wynik'];
}
function get_books_by_subcategory()
{
$widok['center'] = '';
$widok['left'] = $this->get_category();
$widok['right'] = $this->load->view('Ksiegarnia/right', '', true);
$id = $this->uri->segment(3);
if(isset($id) and is_numeric($id))
{
$query = $this->Kategorie_model->get_books_by_subcategory($id, $this->uri->segment(4));
if($query->num_rows() > 0)
{
foreach($query->result() as $item)
{
$widok['center'] .= $this->load->view('Ksiegarnia/get_books', array('data' =>$item), true);
}
}
else
{
$widok['center'] = $this->load->view('Ksiegarnia/get_books', array('tytul' =>'<h1>brak danych</h1>'), true);;
}
$widok['center'] .= $this->pagination->create_links();
$this->load->view('Ksiegarnia/index', $widok);
}
}
这是我的模特:
function get_books_by_subcategory($id, $offset=0)
{
$config['base_url'] = 'http://lukaszbielecki.cba.pl/ksiegarnia/CI/index.php/ksiegarnia/get_books_by_subcategory/'.$id;
$config['per_page'] = 7;
$this->db->where('SUB_CATEGORY_SUBC_ID', $id);
$config['total_rows'] = $this->db->get('books')->num_rows();
$config['num_links'] = 20;
$this->pagination->initialize($config);
return $this->db->get('books',$config['per_page'],$offset);
//$wynik = $this->db->query("Select * from books where SUB_CATEGORY_SUBC_ID = '".$id."'");
//return $wynik;
}
url中的参数正在更改,但仅显示第一个子类别中的项目。 求助。
答案 0 :(得分:0)
在控制器的这一行$widok['center'] = $this->load->view('Ksiegarnia/get_books', array('tytul' =>'<h1>brak danych</h1>'), true);;
上,您有一个额外的分号;
导致语法错误。