ppluobo
发表于 2013-7-8 17:52:39
本帖最后由 ppluobo 于 2013-7-8 17:53 编辑
流浪的乞丐 发表于 2013-7-8 17:45 static/image/common/back.gif
哈哈,先谢谢了。这种方法我之前用过,可行的。 如果最后实在没办法,就采取这个。
翻页后再刷新?不影响查询结果吧,这个跟性能、页面显示什么的也没什么关系。就是代码丑陋,自己偷懒,懒得搞很复杂的方法。
流浪的乞丐
发表于 2013-7-8 17:59:27
ppluobo 发表于 2013-7-8 17:52 static/image/common/back.gif
翻页后再刷新?不影响查询结果吧,这个跟性能、页面显示什么的也没什么关系。就是代码丑陋,自己偷懒,懒 ...
翻页后刷新,会出来个弹出框,询问你是否重复提交表单啥的。我们的测试很给力的。哈哈
gogogo1027
发表于 2013-7-8 18:39:12
本帖最后由 gogogo1027 于 2013-7-8 18:44 编辑
流浪的乞丐 发表于 2013-7-8 17:45 http://codeigniter.org.cn/forums/static/image/common/back.gif
能否贴一些代码,thx
其实你可以按照它的格式来的啊
你的方法就这样
public function page_list($page=1){
$this->load->library('pagination');
$page = max(1,intval($page));//这个为当前页码数
$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = xxx;//数据库获取
$config['per_page'] = 20;
$start = ($page-1)*$config['per_page'];
$sql = "SELECT * FROM table WHERE xxx=xxx AND yyy=yyy LIMIT $start ,$config['per_page']";
$result = $this->db->query($sql)->result_array();
$this->pagination->initialize($config);
$flink = $this->pagination->create_links();
$this->load->view('view_page',array('flink'=>$flink,'data'=>$result));
}
去年明日
发表于 2013-7-12 14:03:23
比如说index根据type和page 来分页就用 CI的路由来传入参数 $type , $page
function index($type='',$page='0')
{
$sql = "select * from users where type ={$type} limit {$page} , 20";
$query = $this->db->query($sql);
$result = $query->result_array();
$this->load->library('pagination');
$config['base_url'] = 'http://example.com/index.php/test/index/$type/';
$config['total_rows'] = $query->num_rows();
$config['per_page'] = 20;
$this->pagination->initialize($config);
echo $this->pagination->create_links();
}
guodong_09
发表于 2013-7-15 17:22:25
我也碰到和楼主一样的问题,搞了好几天没找到好办法。目前是这样的解决方案:
1. 前台如果想URL美观,貌似只能用js自己拼接URL, 然后再submit
2. 后台我是这样解决的。
比如有个连接 http://test.com/admin/category/index.
三个搜索条件:status, parent_id, name
搜索表单用GET提交,然后在controll里获取这3个条件+翻页per_page.
最后生成的翻页连接是: http://test.com/admin/category/index?status=1&parent_id=-1&name=&per_page=2
$page = $this->input->get('per_page'); $page = is_numeric($page) && $page>1 ? $page : 1;
$limit = 20;
$offset = ($page-1)*$limit;
$status = isset($_GET['status']) ? $this->input->get('status') : -1;
$parent_id = isset($_GET['parent_id']) ? $this->input->get('parent_id') : -1;
$name = $this->input->get('name') ? $this->input->get('name') : NULL;
$count = $this->Category->get_categorys($parent_id, $name, $status)->num_rows();
$categorys = $this->Category->get_categorys($parent_id, $name, $status, $limit, $offset)->result();
$this->load->library('pagination');
$config = config_item('pagination');
$config['base_url'] = base_url('admin/category/index')."?status=$status&parent_id=$parent_id&name=".urlencode($name);
$config['total_rows'] = $count;
$config['per_page'] = $limit;
$config['page_query_string'] = TRUE;
$this->pagination->initialize($config);
$pagination = $this->pagination->create_links();
流浪的乞丐
发表于 2013-7-16 11:26:28
guodong_09 发表于 2013-7-15 17:22 static/image/common/back.gif
我也碰到和楼主一样的问题,搞了好几天没找到好办法。目前是这样的解决方案:
1. 前台如果想URL美观,貌似 ...
THX.
我就是这么解决的,但是还是觉得有点怪怪的。不知道你是怎么处理的。
我觉得怪的地方:如果我没有搜索条件,我的链接是http://test.com/admin/category/index?&per_page=2,我想我的链接是http://test.com/admin/category/index?per_page=2,但是无论我如何写$config['base_url'],都没办法满足(去掉&)
guodong_09
发表于 2013-7-18 09:25:40
流浪的乞丐 发表于 2013-7-16 11:26 static/image/common/back.gif
THX.
我就是这么解决的,但是还是觉得有点怪怪的。不知道你是怎么处理的。
这个貌似没办法,除非去重写CI的翻页类。
还有一个想法,如果程序允许前台和后台分开,也就是2个APPLICATION,那样的话就可以单独配置config。
前台用$config['enable_query_strings'] = false;
后台用$config['enable_query_strings'] = true;
后台就不重写了,直接用原始的URL拼接,http://www.test.com/index.php?m=admin&c=xxx&m=xxx¶m1=xxx&prams2=xxx
xuz0917
发表于 2013-7-18 11:01:13
我是用的GET
、林神奇
发表于 2013-7-19 00:07:40
guodong_09 发表于 2013-7-15 17:22 static/image/common/back.gif
我也碰到和楼主一样的问题,搞了好几天没找到好办法。目前是这样的解决方案:
1. 前台如果想URL美观,貌似 ...
请问 $page = $this->input->get('per_page'); 这个值是怎么来的呢?表单get过来?
guodong_09
发表于 2013-7-19 09:22:48
、林神奇 发表于 2013-7-19 00:07 static/image/common/back.gif
请问 $page = $this->
开启了$config['page_query_string' = TRUE;之后,
翻页链接会加上http://www.test.com/admin/category/index?&per_page=X
然后你就可以GET获取了