yoyoyuye 发表于 2018-3-4 14:04:16

CI 3.1.7 分页类使用

控制器的代码:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {
        function _construct(){
                        parent::_construct();
                        header('Content-type:text/html; charset=utf-8');
                        $this->load->database();
                        $this->load->helper('url_helper');
                        $this->load->library('pagination');
        }
        public function index(){
                $this->load->model('Ssqsearch');
                $config['base_url'] = 'http://www.fucai56.com/';
                $config['total_rows'] = $this->Ssqsearch->count_table();
                $config['per_page'] = 20;
                $this->pagination->initialize($config);
                $data['pageinfo']=$this->pagination->create_links();
                $limit=20;
                $offset=$this->uri->segment(3);
                $data['news'] = $this->Ssqsearch->show_data($limit,$offset);
                $this->load->view('header');
                $this->load->view('index',$data);
                $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);

yx1hlqbk 发表于 2018-3-6 13:24:05

我建議你重新寫一個比較實在

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

如果要針對個人化,重寫會比較好

Hex 发表于 2018-3-7 00:32:26

构造函数写错了,是两个下划线,不是一个,正确写法:function __construct() {}
页: [1]
查看完整版本: CI 3.1.7 分页类使用