2

我有一个页面,其中书籍将以“网格”视图或“列表”视图显示。

所以我当前的网址是 http://localhost/thebestbookfinder.com/viewallbooks/books/pgn/grid/8

如果我从我的视图页面单击“列表”链接,那么我的当前页面应该加载,只需将此部分更改/grid//list/和其他相同。IEhttp://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>

如果表单提交解决了我的问题,而不是链接,那么请帮助我

控制器.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);  
          }
}
4

3 回答 3

1

需要像这样在 route.php 中添加路由

$route['viewallbooks/books/(:any)'] = "viewallbooks/books/$1";

函数 book() 默认包含 3 个带值的参数
下面是更正确的变量

    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);
        }
于 2013-02-03T13:27:56.443 回答
0

您必须执行以下任一操作:

  • 使用新的 url(网格)重新加载页面以呈现该模板

或者:

  • 渲染网格和列表视图,然后根据您想要看到的内容动态地(使用一些 css/javascript)隐藏内容。

或者:

  • 使用 AJAX 加载网格视图并用它替换列表。
于 2013-02-03T12:22:22.767 回答
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' => ''))."";  ?>

并且无需更改上述控制器中的任何内容。

于 2013-02-04T04:57:01.820 回答