2013-10-01 84 views
0

我可以通過向CI config.php文件添加後綴「.html」來製作一個頁面example.com/index.php/products/view/shoes作爲example.com/index.php/products/view/shoes.html 。 [Ref:http://ellislab.com/codeigniter/user-guide/general/urls.html]如何在URL中的分頁鏈接中包含URL後綴?

但是,當我在分頁中生成鏈接後綴不會添加到生成的鏈接到其他頁面。

是否有任何設置可以通過配置來完成,或者我們是否需要修改庫文件。

+0

你是什麼意思的「後綴」?你可以請張貼一些例子或代碼在這裏。 – ABorty

+0

更新了更多細節。 – Nishanthan

回答

3

您可以定義分頁鏈接後綴是這樣的:

$config['suffix'] = YOUR_SUFFIX 

看我的例子:

網址: http://www.test_store.com/products/index/order/low_price

// Parsing the URI 
$uri = $this->uri->uri_to_assoc(3); 

$page  = !empty($uri['page']) ? $uri['page'] : 1; 
$order = !empty($uri['order']) ? $uri['order'] : false; 

// Search paginated 
$this->Product->limit = $per_page; 
$this->Product->offset = ($page - 1) * $per_page; 
$this->Product->order = $order; 

$products = $this->Product->get_all(); 

// Pagination config 
$config['base_url']   = site_url('products/index/page'); 
$config['total_rows']  = $this->Product->count_all(); 
$config['uri_segment']  = 4; 
$config['num_links']  = 5; 
$config['use_page_numbers'] = TRUE; 
$config['per_page']   = $per_page; 

// Add a suffix to pagination links 
$config['suffix'] = !empty($uri['order']) ? '/order/'. $uri['order'] : ''; 

$this->pagination->initialize($config); 

$pagination = $this->pagination->create_links(); 

PD:我是阿根廷人,我的英語能力有點差

+0

如果我通過擴展名傳遞基礎url,那麼它沒有不工作,否則工作正常。但是,對於第一頁,我不會在base_url中傳遞它時獲得後綴。我怎樣才能做到這一點? – Nishanthan

+0

你可以這樣附加擴展名:$ config ['suffix'] ='.html'; – ggallohernandez

+0

它適用於頁面,但不適用於第一頁。第一頁只獲得base_url。 – Nishanthan

0

在你的application/config/config.php文件:

/* 
|-------------------------------------------------------------------------- 
| URL suffix 
|-------------------------------------------------------------------------- 
| 
| This option allows you to add a suffix to all URLs generated by CodeIgniter. 
| For more information please see the user guide: 
| 
| http://codeigniter.com/user_guide/general/urls.html 
*/ 

$config['url_suffix'] = ''; 
+0

正如我在問題中所解釋的,這對於使用anchor()函數生成的鏈接有效,但對分頁中的鏈接不起作用。 – Nishanthan

+0

發佈你的分頁代碼。對於分頁,你需要手動創建它們。 –

+0

在分頁中,我傳遞了base_url而沒有後綴,否則它會生成諸如www.example.com/controller/method.html/page/1之類的代碼,這些代碼無效。我想生成諸如www.example.com/controller/method/page/1.html之類的代碼,但是我找不到任何pagination中的後綴參數來傳遞擴展名base_url – Nishanthan