CodeIgniter 3 无法在实时服务器上扩展库

CodeIgniter 3 Unable to extend library on live server

我在 MY_pagination 库中扩展了 CI_pagination。它在 wamp 中离线工作正常。但是我不知道为什么它不能在实时服务器上在线工作。

MY_pagination.php

    <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class MY_pagination extends CI_pagination {
        protected $CI;

        public function __construct() {
            parent::__construct();
                // reference to the CodeIgniter super object
            $this->CI =& get_instance();

         }



         public function table_pagination($page_url, $total_rows, $per_page)
        {

            $config = array(
                'base_url' => $page_url,
                'total_rows' => $total_rows,
                'per_page' => $per_page,
                'use_page_numbers' => TRUE,
                'num_links' => 2,

                'next_link' => 'Next',
                'prev_link' => 'Previous',
                'reuse_query_string' => true,
                'first_link' => false,
                'last_link' => false,

                'full_tag_open' => '<ul class="pagination">',
                'full_tag_close' => '</ul>',
                'next_tag_open' => '<li class="paginate_button next" id="example1_next">',
                'next_tag_close' => '</li>',
                'prev_tag_open' => '<li class="paginate_button previous" id="example1_previous">',
                'prev_tag_close' => '</li>',
                'cur_tag_open' => '<li class="paginate_button active"><a>',
                'cur_tag_close' => '</a></li>',
                'num_tag_open' => '<li class="paginate_button">',
                'num_tag_close' => '</li>'
            );

            $this->CI->pagination->initialize($config);
            return $this->CI->pagination->create_links();


        }

     public function home_pagination($page_url, $total_rows, $per_page)
        {

            $config = array(
                 'prefix' => 'page/',
                'base_url' => $page_url,
                'total_rows' => $total_rows,
                'per_page' => $per_page,
                'use_page_numbers' => TRUE,
                'num_links' => 2,

                'next_link' => '<img src="'.base_url('assets/images/arrow-next-small.png').'" alt=""/>',
                'prev_link' => '<img src="'.base_url('assets/images/arrow-pre-small.png').'" alt=""/>',
                'reuse_query_string' => true,
                'first_link' => false,
                'last_link' => false,

                'full_tag_open' => '<div class="pagination">',
                'full_tag_close' => '</div>',
                'next_tag_open' => '',
                'next_tag_close' => '',
                'prev_tag_open' => '',
                'prev_tag_close' => '',
                'cur_tag_open' => '<a href="#" class="active">',
                'cur_tag_close' => '</a>',
                'num_tag_open' => '',
                'num_tag_close' => ''
            );

            $this->CI->pagination->initialize($config);
            return $this->CI->pagination->create_links();


        }

    }

Home_controller.php

<?php
class Home_controller extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->library('pagination');
        $this->load->helper('date');
        $this->load->helper('main');
        $this->load->helper('cookie');
        $this->load->helper('template_helper');
        $this->load->helper('db_helper');
        $remember_me = get_cookie('user_remember');
        _session_login($remember_me);
        $this->load->library('session');

        // _valid_session_login_check();
        //  $this->load->model('admin_models/sliders/slider_model');

    }

    public function index()
    {
        $controller_base_url = base_url("/front_controllers/home/home_controller/index");
        $controller_re_url   = base_url("/index");
        $uri_values          = $this->uri->uri_to_assoc(2);
        $search_string       = "";
        if (isset($uri_values['search'])) {
            $search_string = $uri_values['search'];
        }

        $page_num = 1;
        if (isset($uri_values['page'])) {
            $page_num = $uri_values['page'];
        }

        $page_url = $controller_re_url;
        if ($search_string !== "") {
            $page_url = $page_url . "/search/" . $search_string;
        }

        if (!isset($uri_values['search'])) {
            $search_string = $this->input->get('search');
        }

        $per_page = 12;
        if ($search_string == "") {
            $post_list  = _get_post_list($per_page, $page_num);
            $total_rows = _post_rows_count("active", "");
        } else {
            $post_list  = _post_search($search_string, $per_page, $page_num);
            $total_rows = _home_search_rows_count($search_string);
        }

        $active_post_pagination = $this->pagination->home_pagination($page_url, $total_rows, $per_page);
        $cat_list               = _get_term_list_post_count('category', 0, 1);
        $tag_list               = _get_term_list_post_count('tag', 10, 1);

        // print_r($post_list);

        $urls       = array(
            'controller_base_url' => $controller_base_url,
            'controller_re_url' => $controller_re_url
        );
        $this->data = array(
            'urls' => $urls,
            'post_list' => $post_list,
            'widget_cat_list' => $cat_list,
            'widget_tag_list' => $tag_list,
            'active_post_pagination' => $active_post_pagination
        );
        $this->meta = 'layout/front_layout/normal_meta';
        $this->head = 'layout/front_layout/home/home_view_head_section';
        $this->body = 'layout/front_layout/home/home_view_content_section';
        $this->layout();
    }
}

?>

错误

Fatal error: Call to undefined method CI_Pagination::home_pagination() in /home/lovebatth39/public_html/application/controllers/front_controllers/home/Home_controller.php on line 55

我不知道为什么它不能在线工作。主要是我想扩展分页库。我已经检查了像 capital MY_

这样的命名系统

$config['subclass_prefix'] = 'MY_';

配置文件也设置为 MY_

CI 在实时服务器上完全忽略 MY_pagination.phpMY_pagination.php,无论我在文件中放了什么

尝试将分页库文件重命名为 MY_Pagination.php 并更改以下行:

class MY_pagination extends CI_pagination {  

class MY_Pagination extends CI_Pagination {
  1. 将名称 MY_pagination 更改为 MY_Pagination,将 CI_pagination 更改为 CI_Pagination
  2. $this->load->library('pagination');更改为$this->load->library('my_pagination');

其他答案表明您使用了不正确的文件和 class 命名。此外,您 MY_Pagination 的结构不正确。因为它扩展了 class,所以该基 class 的所有属性和方法都可用。

这是定义文件的方式。请注意 此文件的存储位置 以及 class 声明行的大写。

文件:/application/libraries/MY_Pagination.php

<?php

if(!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Pagination extends CI_Pagination
{
// $CI and __construct() are not needed here. The parent class has them 
//  protected $CI;
//
//  public function __construct()
//  {
//      parent::__construct();
//      // reference to the CodeIgniter super object
//      $this->CI = & get_instance();
//  }

    public function table_pagination($page_url, $total_rows, $per_page)
    {
        $config = array(
            'base_url' => $page_url,
            'total_rows' => $total_rows,
            'per_page' => $per_page,
            'use_page_numbers' => TRUE,
            'num_links' => 2,
            'next_link' => 'Next',
            'prev_link' => 'Previous',
            'reuse_query_string' => true,
            'first_link' => false,
            'last_link' => false,
            'full_tag_open' => '<ul class="pagination">',
            'full_tag_close' => '</ul>',
            'next_tag_open' => '<li class="paginate_button next" id="example1_next">',
            'next_tag_close' => '</li>',
            'prev_tag_open' => '<li class="paginate_button previous" id="example1_previous">',
            'prev_tag_close' => '</li>',
            'cur_tag_open' => '<li class="paginate_button active"><a>',
            'cur_tag_close' => '</a></li>',
            'num_tag_open' => '<li class="paginate_button">',
            'num_tag_close' => '</li>'
        );

        //initialize() and create_links() are part of "this" class
        $this->initialize($config);
        return $this->create_links();
    }

    public function home_pagination($page_url, $total_rows, $per_page)
    {

        $config = array(
            'prefix' => 'page/',
            'base_url' => $page_url,
            'total_rows' => $total_rows,
            'per_page' => $per_page,
            'use_page_numbers' => TRUE,
            'num_links' => 2,
            'next_link' => '<img src="'.base_url('assets/images/arrow-next-small.png').'" alt=""/>',
            'prev_link' => '<img src="'.base_url('assets/images/arrow-pre-small.png').'" alt=""/>',
            'reuse_query_string' => true,
            'first_link' => false,
            'last_link' => false,
            'full_tag_open' => '<div class="pagination">',
            'full_tag_close' => '</div>',
            'next_tag_open' => '',
            'next_tag_close' => '',
            'prev_tag_open' => '',
            'prev_tag_close' => '',
            'cur_tag_open' => '<a href="#" class="active">',
            'cur_tag_close' => '</a>',
            'num_tag_open' => '',
            'num_tag_close' => ''
        );

        $this->initialize($config);
        return $this->create_links();
    }
}

在控制器中 $this->load->library('pagination'); 将识别出 MY_pagination.php 存在并加载它。使用 $this->load->library('my_pagination'); 会失败。

附带说明一下,您的控制器名称很笨拙。就用这个

class Home extends MY_Controller 

您可以使用 https://example.com/home 之类的 URL 而不是 https://example.com/home_controller。在我看来,这看起来很愚蠢。