2013-10-01 86 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