Extiendo CI_pagination en la biblioteca MY_pagination. funciona bien sin conexión en wamp. Pero no sé por qué no funciona en línea en el servidor en vivo.

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();
    }
}

?>

Error

Error fatal: Llame al método indefinido CI_Pagination :: home_pagination () en /home/lovebatth39/public_html/application/controllers/front_controllers/home/Home_controller.php en la línea 55

No sé por qué no funciona en línea. Principalmente estoy tratando de extender la biblioteca de paginación. Ya verifiqué el sistema de nombres como mayúscula MY_

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

El archivo de configuración también está configurado en MY_

CI ignorando MY_pagination.php o MY_pagination.php por completo en el servidor en vivo sin importar lo que ponga en el archivo

-2
Lovepreet Singh Batth 19 ene. 2018 a las 14:32

3 respuestas

La mejor respuesta

Intente cambiar el nombre del archivo de la biblioteca de paginación a MY_Pagination.php y cambie la línea a continuación:

class MY_pagination extends CI_pagination {  

Para

class MY_Pagination extends CI_Pagination {
1
Hasta Dhana 19 ene. 2018 a las 11:54

Como las otras respuestas indican que está usando un nombre de archivo y clase incorrecto. Además, ha estructurado MY_Pagination incorrectamente. Debido a que extiende una clase, todas las propiedades y métodos de esa clase base están disponibles.

Aquí está la forma en que se debe definir el archivo. Presta atención a donde este archivo está almacenado y a la mayúscula de línea de declaración de clase.

Archivo: /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();
    }
}

En el controlador, $this->load->library('pagination'); reconocerá que existe MY_pagination.php y lo cargará. Usar $this->load->library('my_pagination'); fallará.

Como nota al margen, el nombre de su controlador es torpe. Solo usa esto

class Home extends MY_Controller 

Puede usar URL como https://example.com/home en lugar de https://example.com/home_controller. Lo cual, en mi opinión, parece tonto.

1
DFriend 19 ene. 2018 a las 17:32
  1. Cambie los nombres MY_pagination a MY_Pagination y CI_pagination a CI_Pagination.
  2. Cambie $this->load->library('pagination'); a $this->load->library('my_pagination');
0
Sushant Pimple 19 ene. 2018 a las 12:18