我有一个页面,可以使用“网格”视图或“列表”视图显示书籍。
所以我现在的网址是
http://localhost/thebestbookfinder.com/viewallbooks/books/pgn/grid/8
如果我点击我的视图页面中的“列表”链接,那么我的当前页面应加载,只需将此部分/grid/
更改为/list/
,其他相同。
即http://localhost/thebestbookfinder.com/viewallbooks/books/pgn/list/8
我尝试了这个,但这没有用。请帮我解决这个问题。
inMyViewPage.php
<td width="10%" style="font-size:12px;color: red;">
<?php
echo "".anchor('#', 'Grid', array('id' => ''))."";
echo "".anchor(base_url().'viewallbooks/books/pgn/'.$this->uri->segment(4),' List', array('id' => ''))."";
?>
</td>
如果表单子目标解决了我的问题而不是链接,那么请帮助我
Controller.php这样
function books()
{
$config = array();
$config['base_url'] = base_url().'viewallbooks/books/pgn/'.$this->uri->segment(4);
$config["total_rows"] = $this->Booksmodel->record_count_for_secondtopBooks('3');
$config['uri_segment'] = 5;
$config['per_page'] = 8;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
$data["query"] = $this->Subjectmodel->get_subjects();
$data["query1"]= $this->Editionmodel->get_edition();
$data["query2"]=$this->Booksmodel->get_all_book_list_atHomeTop('3',$config["per_page"], $page);
$viewType = ($this->uri->segment(4)) ? $this->uri->segment(4) : 'list';
if($viewType=='list')
{
$this->load->view('commonfiles/bookslistview',$data);
}
else {
$this->load->view('commonfiles/booksgridview',$data);
}
}
答案 0 :(得分:1)
需要在route.php中添加路由,如此
$route['viewallbooks/books/(:any)'] = "viewallbooks/books/$1";
函数书籍()shold包含3个参数,默认情况下为值 下面是更正确的varian
function books($img_type = 'png', $view_type = 'list', $page = 0) {
$config = array();
$config['base_url'] = base_url().'viewallbooks/books/'.$img_type.'/'.$view_type.'/'.$page;
$config["total_rows"] = $this->Booksmodel->record_count_for_secondtopBooks('3');
$config['uri_segment'] = 5;
$config['per_page'] = 8;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data["query"] = $this->Subjectmodel->get_subjects();
$data["query1"]= $this->Editionmodel->get_edition();
$data["query2"]= $this->Booksmodel->get_all_book_list_atHomeTop('3',$config["per_page"], $page);
if($viewType=='list')
$this->load->view('commonfiles/bookslistview',$data);
else
$this->load->view('commonfiles/booksgridview',$data);
}
答案 1 :(得分:0)
你必须这样做:
OR:
或者:
答案 2 :(得分:0)
这样做:
<?php echo "".anchor(base_url().'viewallbooks/books/pgn/grid/'.$this->uri->segment(5),' Grid', array('id' => ''))."";
echo "".anchor(base_url().'viewallbooks/books/pgn/list/'.$this->uri->segment(5),' List', array('id' => '')).""; ?>
无需更改控制器上方的任何内容。