|
本帖最后由 wingofsky 于 2013-7-10 14:24 编辑
【我是产品经理不是科班开发人员,如思路有问题,代码不严谨欢迎指正,谢谢】
CI:2.1.3
CSS:bootstrap
PHP复制代码
//配置
$config['enable_query_strings'] = TRUE;
复制代码
PHP复制代码
//分页,此处我自定义了一个helper,用来申明分页相关信息
function helper_pagination ($url='',$total_rows=0)
{
$CI =& get_instance ();
$CI->load->library('pagination');
$config['base_url'] = $url;
$config['full_tag_open'] = '<div class="pagination"><ul>';
$config['full_tag_close'] = '</ul></div>';
$config['first_link'] = '第一页';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a>';
$config['cur_tag_close'] = '</a></li>';
$config['prev_link'] = '上一页';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '下一页';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['last_link'] = FALSE;
$config['total_rows'] = $total_rows;
$config['per_page'] = 20;
$CI->pagination->initialize($config);
return $CI->pagination->create_links();
}
//分析URL,提取参数
function helper_url_tool ($url)
{
$new_url = '';
$url = explode('?', $url);//以问号分解当前链接
$base_url = $url[0];//基础地址,先保留可能以后会用
$url = explode('&', $url[1]);//以&分解参数字符串
foreach ($url as $value) {
if (!stristr($value, 'per_page=')) {
$new_url .= $value.'&';//将参数连接
}
}
//$new_url = $base_url.'?'.$new_url;
$new_url = '?'.$new_url;//只保留参数部分
return trim($new_url,'&');//去除最后一个&
}
复制代码
PHP复制代码
//控制器内调用
$url = helper_url_tool($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);//分解当前地址
$total_rows = $this->mcity->getCity_num();//总行数
$data['pagination'] = helper_pagination($url=$url,$total_rows);
复制代码
PHP复制代码
//视图内输出:
<?php echo $pagination;?>
复制代码
|
评分
-
查看全部评分
|