【发布时间】:2013-04-28 18:51:10
【问题描述】:
我想在生成的分页链接末尾添加一些字符串/值。 例如,我得到了这个
http://localhost/products/lists/5
我想拥有
http://localhost/products/lists/5/value/anothervalue
所以,我需要以某种方式发送这些值... :)
谢谢大家。
【问题讨论】:
我想在生成的分页链接末尾添加一些字符串/值。 例如,我得到了这个
http://localhost/products/lists/5
我想拥有
http://localhost/products/lists/5/value/anothervalue
所以,我需要以某种方式发送这些值... :)
谢谢大家。
【问题讨论】:
分页类有一个名为 suffix 的未记录配置选项,您可以使用它。以下是我在其中一款应用中使用它的方式:
// get the current url segments and remove the ones before the suffix
// http://localhost/products/lists/5/value/anothervalue
$args = $this->uri->segment_array();
unset($args[1], $args[2], $args[3]);
$args = implode('/', $args);
// $args is now 'value/anothervalue'
$base_url = 'http://localhost/products/lists';
$this->pagination->initialize(array(
'base_url' => $base_url,
'suffix' => '/'.$args,
'first_url' => $base_url.'/1/'.$args,
'uri_segment' => 3
));
【讨论】:
application/config/routes.php
$route['products/lists/(:num)/value/(:any)'] = "products/lists/$1/$2";
控制器代码application/controllers/products.php
class Products extends CI_Controller {
public function index() {
$this->load->view('welcome_message');
}
public function lists($page = 1, $value = null) {
$this->load->view('product_lists', array('page' => $page, 'value' => $value));
}
}
这样如果你的网址是http://localhost/products/lists/5/value/anothervalue
在函数 lists 中将是 $page = 5 和 $value = 'anothervalue' 并且它们将在模板 product_lists ($page, $value) 中可用
【讨论】: