2011-11-07 37 views
1

在我笨應用程序,我有一篇文章模塊,其中有三類,笨分頁動態的URL結構

主要類別 二級類別 第三類的文章 列表

現在,第一頁顯示的除了文章列表以外,還可以使用手寫符號,用戶可以直接點擊展開或點擊分類名稱。

因此,如果用戶點擊主類別名稱,所有文章將基於codeigniter的內置分頁庫列出分頁。

同樣,如果單擊第三個類別中的文章,將單獨列出。問題是所有的文章列表是由一個函數處理,因此我有這樣的路線。

$route['article/(:any)/(:any)/(:any)/(:any)'] = "articles/articles/show_article/$4"; 
$route['article/(:any)/(:any)/(:any)'] = "articles/articles/find_type/$3"; 
$route['article/(:any)/(:any)'] = "articles/articles/find_type/$2"; 
$route['article/(:any)'] = "articles/articles/find_type/$1"; 

和我find_type方法是

function find_type($str) 
    { 
     $rawstr = $str; 
     $str = deurl($str); 
     $ch = 1; 
     $id = 0; 
     $query = $this->db->get_where("articles_primary",array("primary_name"=>$str)); 
     if($query->num_rows==1) { 
      $ch = 1; 
      $id = $query->row('id'); 
     } 
     $query = $this->db->get_where("articles_secondary",array("secondary_name"=>$str)); 
     if($query->num_rows==1) { 
      $ch = 2; 
      $id = $query->row('id'); 
     } 
     $query = $this->db->get_where("articles_tertiary",array("tertiary_name"=>$str)); 
     if($query->num_rows==1) { 
      $ch = 3; 
      $id = $query->row('id'); 
     } 
     $query = $this->db->get_where("articles_list",array("url_title"=>$rawstr)); 
     if($query->num_rows==1) { 
      $ch = 4; 
     } 
     switch ($ch) 
     { 
      case 1: 
       $this->show_articles_list($id,"primary",$rawstr); 
       break; 
      case 2: 
       $this->show_articles_list($id,"secondary",$rawstr); 
       break; 
      case 3: 
       $this->show_articles_list($id,"tertiary",$rawstr); 
       break; 
      case 4: 
       $this->show_article($rawstr); 
       break; 
     } 
    } 

最後名單的文章是

function show_articles_list($id,$tbl,$rawstr) 
    { 
     $query = $this->db->get_where("articles_list",array($tbl."_id"=>$id)); 

     $this->load->library('pagination'); 
     $config['base_url'] = current_url(); 
     $config['total_rows'] = $query->num_rows; 
     $config['per_page'] = 9; 
     $this->pagination->initialize($config); 
     $page = $this->uri->segment(3); 

     if($page=="") { $page = 0; } 
     $this->db->limit(9,$page); 
     $data["query"] = $this->db->get_where("articles_list",array($tbl."_id"=>$id)); 

     $this->template->write_view('maincontent', 'articles/articles_list',$data); 
     //$this->template->write_view('subcontent', 'articles/related_articles',$data); 
     $this->template->write("title","Laws",true); 
     $this->template->write_view('rightcontent','general/include/query_document_tab'); 
     $this->template->render(); 
    } 

正如你所看到的路線是基於URI段,因此分頁不工作。無論如何,我可以調整分頁以適應當前的設置嗎?

回答

0

如何添加其他參數的功能和改變路線相應文件:

function find_type($str, $page=0){ 
... 
$this->show_articles_list($id,"primary",$rawstr, $page); 
etc... 
... 
} 

function show_articles_list($id,$tbl,$rawstr,$page)... 

路線:

$route['article/(:any)/(:any)/(:any)/(:any)'] = "articles/articles/show_article/$4/4"; 
$route['article/(:any)/(:any)/(:any)'] = "articles/articles/find_type/$3/3"; 
$route['article/(:any)/(:any)'] = "articles/articles/find_type/$2/2"; 
$route['article/(:any)'] = "articles/articles/find_type/$1/1"; 

你會使用這個參數來表示了分頁URI段。

OR

你可以只使用$this->uri->total_segments()