用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1817|回复: 2
收起左侧

[版本 3.x] CI 3.1.7 分页类使用

[复制链接]
发表于 2018-3-4 14:04:16 | 显示全部楼层 |阅读模式
控制器的代码:
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');

  3. class Home extends CI_Controller {
  4.         function _construct(){
  5.                         parent::_construct();
  6.                         header('Content-type:text/html; charset=utf-8');
  7.                         $this->load->database();
  8.                         $this->load->helper('url_helper');
  9.                         $this->load->library('pagination');
  10.         }
  11.         public function index(){
  12.                 $this->load->model('Ssqsearch');
  13.                 $config['base_url'] = 'http://www.fucai56.com/';
  14.                 $config['total_rows'] = $this->Ssqsearch->count_table();
  15.                 $config['per_page'] = 20;
  16.                 $this->pagination->initialize($config);
  17.                 $data['pageinfo']=$this->pagination->create_links();
  18.                 $limit=20;
  19.                 $offset=$this->uri->segment(3);
  20.                 $data['news'] = $this->Ssqsearch->show_data($limit,$offset);
  21.                 $this->load->view('header');
  22.                 $this->load->view('index',$data);
  23.                 $this->load->view('footer');
复制代码

一直提示第17行错误,初始化失败。

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Home:pagination

Filename: controllers/Home.php

Line Number: 17

Backtrace:

File: D:\web\ssq\application\controllers\Home.php
Line: 17
Function: _error_handler

File: D:\web\ssq\index.php
Line: 315
Function: require_once

但是我看手册,还有其他人的例子,都是这样初始化的。        $this->pagination->initialize($config);
发表于 2018-3-6 13:24:05 | 显示全部楼层
我建議你重新寫一個比較實在

CI內建的分頁系統有些不完善

如果要針對個人化,重寫會比較好
发表于 2018-3-7 00:32:26 | 显示全部楼层
构造函数写错了,是两个下划线,不是一个,正确写法:function __construct() {}

本版积分规则