CodeIgniter 自带分类详解及如何一直显示首页和尾页
2013-08-07 18:56
381 查看
控制器
如想一直显示首页和尾页--》打开分页类318行改成if ($this->last_link !== FALSE)
首页229行改成 if ($this->first_link !== FALSE )
就是说去掉后边的and判断
public function index($p=1){ // $data['news'] = $this->news_model->get_news(); //echo $p; $data['title'] = '标题'; //分页使用 $res = $this->db->get('news');//进行一次查询 $config['base_url'] = '/ci/index.php/news/index';//设置分页的url路径 $config['uri_segment'] = 3; //设置url上第几段用于传递分页器的偏移量 $config['total_rows'] = $res->num_rows();//得到数据库中的记录的总条数 $config['per_page'] = '2';//每页记录数 $config['first_link'] = '首页'; $config['last_link'] = '尾页'; $config['full_tag_open'] = '<p>'; $config['full_tag_close'] = '</p>'; $config['next_link'] = '下一页'; $config['prev_link'] = '上一页'; $config['use_page_numbers'] = TRUE;//必须加上要不页码会乱... //$config['num_links'] = 4;//配置分页导航当前页两边显示的条数 $start=($p-1)*$config['per_page']; $this->pagination->initialize($config);//分页的初始化 //$data['news']= $this->news_model->get_news($config['per_page'],$this->uri->segment(3));//得到数据库记录 $data['news']= $this->news_model->get_news($config['per_page'],$start);//得到数据库记录 //分页结束 $this->load->view('templates/header', $data); $this->load->view('news/index', $data); $this->load->view('templates/footer'); } public function view($id){ $data['news_item'] = $this->news_model->view_news($id); if (empty($data['news_item'])) { show_404(); } $data['title'] = $data['news_item']['title']; $this->load->view('templates/header', $data); $this->load->view('news/view', $data); $this->load->view('templates/footer'); } public function create() { $this->load->helper('form'); $this->load->library('form_validation'); $data['title'] = 'Create a news item'; $this->form_validation->set_rules('title', 'Title', 'required'); $this->form_validation->set_rules('text', 'text', 'required'); if ($this->form_validation->run() === FALSE) { $this->load->view('templates/header', $data); $this->load->view('news/create'); $this->load->view('templates/footer'); } else { $this->news_model->set_news(); $this->load->view('news/success'); } }
模型
<?php class News_model extends CI_Model { public function __construct() { $this->load->database(); } public function get_news($num,$offset){ //从数据库中取数据,$num表示取得的数目,$offset表示从什么地方开始取 $query = $this->db->get('news',$num,$offset); return $query->result_array(); /* if ($slug === FALSE) { $query = $this->db->get('news'); return $query->result_array(); } $query = $this->db->get_where('news', array('slug' => $slug)); return $query->row_array(); */ } public function view_news($id) { $query = $this->db->get_where('news', array('id' => $id)); return $query->row_array(); } public function set_news() { $this->load->helper('url'); $slug = url_title($this->input->post('title'), 'dash', TRUE); $data = array( 'title' => $this->input->post('title'), 'slug' => $slug, 'text' => $this->input->post('text') ); return $this->db->insert('news', $data); } }
视图
<?php foreach ($news as $news_item): ?>
<h2><?php echo $news_item['title'] ?></h2>
<div id="main">
<?php echo $news_item['text'] ?>
</div>
<p><a href="/ci/index.php/news/view/<?php echo $news_item['id'] ?>">
View article 详细信息</a></p>
<?php endforeach ?>
<hr>
<?php echo $this->pagination->create_links();?>
相关文章推荐
- 如何处理wordpress首页不显示指定分类文章
- 如何让WordPress首页不显示指定分类的文章
- ECSHOP:如何实现首页显示子分类并用标签页显示
- 如何处理wordpress首页不显示指定分类文章
- zen cart在首页指定新进产品显示某个分类下面的产品
- 如何通过动态生成Html灵活实现DataGrid分类统计的界面显示功能
- winform 入门开发,VS 程序自带的日历控件日期显示格式是xxxx年x月x日,如何改成xxxx-xx-xx 的格式 ?
- phpcms-v9中首页、频道页、列表页如何显示文章的浏览量和评论数
- login控件 登陆图片居右显示 登陆窗口不管分辨率,窗口如何变化,一直居中显示
- 为DataGrid的自带分页添加首页、尾页及状态功能
- 如何使UIScrollView的滚动条indicator一直显示
- ecshop ecs_template 解释 作用,数据字段 首页自定义分类显示,美乐乐
- 如何通过动态生成Html灵活实现DataGrid分类统计的界面显示功能
- 为DataGrid的自带分页添加首页、尾页及状态功能
- EcShop首页显示特定分类的精品新品热销特价等推荐商品
- MySQL分类汇总(group by...with rollup)统计时,如何显示“总计”字段?
- 如何使UIScrollView的滚动条indicator一直显示
- Spark Mllib里如何对决策树二元分类和决策树多元分类的分类数目numClasses控制(图文详解)
- Android中SurfaceView的使用详解及如何在jni(hal层)直接显示
- 如何给DataGrid添加两个的题头分类显示