Codeigniter库无法正常工作

时间:2015-10-31 09:02:06

标签: codeigniter

正在使用codeigniter自定义库。我附上了库函数和控制器函数以及我的帖子。

我的代码

控制器: -

public function __construct()
{
    parent::__construct();
    $this->load->library('pagination_library');
}

function index(){
   $this->pagination_library->orders();
}

Pagination_library:

class Pagination_library {

  function __construct() {
    parent::__construct();
    $this->CI =& get_instance();
    $this->CI->load->model('pagination_model');
    $this->CI->load->library('pagination');
  }

  public function orders(){
  }

}

我收到此错误:

  

致命错误:当前类范围没有时,无法访问parent ::   父

4 个答案:

答案 0 :(得分:1)

您没有从任何其他类扩展此类。所以parent ::不起作用。试试这个。如果您在创建库Link

时仍遇到任何问题,请按照本教程进行操作
   public function orders()
  {
    $this->CI =& get_instance();
    $this->CI->load->model('pagination_model');
    $this->CI->load->library('pagination');
   }

答案 1 :(得分:0)

这样做:

class Pagination_library { 

function __construct() 
  {
    // parent::__construct();
    $this->CI =& get_instance();
    $this->CI->load->model('pagination_model');
    $this->CI->load->library('pagination');
  }
  public function orders()
  {

  }

}

答案 2 :(得分:0)

public function pager($total,$segment=3,$perpage=PP){

    $this->load->library('pagination');
    if($segment==3){
        $config['base_url'] = base_url($this->uri->segment(1).'/'.$this->uri->segment(2));
    }elseif($segment == 4){
        $config['base_url'] = base_url($this->uri->segment(1).'/'.$this->uri->segment(2).'/'.$this->uri->segment(3));
    }elseif($segment==5){
        $config['base_url'] = base_url($this->uri->segment(1).'/'.$this->uri->segment(2).'/'.$this->uri->segment(3).'/'.$this->uri->segment(4));
    }elseif($segment==2){
        $config['base_url'] = base_url($this->uri->segment(1).'/');
    }
    $config['uri_segment'] = $segment;

    $config['total_rows'] = $total;
    $config['per_page'] = $perpage;

    $config['full_tag_open'] = '<ul class="pagination">';
    $config['full_tag_close'] = '</ul>';

    $config['first_link'] = '&laquo;';
    $config['first_tag_open'] = '<li>';
    $config['first_tag_close'] = '</li>';

    $config['last_link'] = '&raquo;';
    $config['last_tag_open'] = '<li>';
    $config['last_tag_close'] = '</li>';

    $config['next_link'] = '&rarr;';
    $config['next_tag_open'] = '<li>';
    $config['next_tag_close'] = '</li>';

    $config['prev_link'] = '&larr;';
    $config['prev_tag_open'] = '<li>';
    $config['prev_tag_close'] = '</li>';

    $config['cur_tag_open'] = '<li class="active"><a href="#">';
    $config['cur_tag_close'] = '</a></li>';

    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';

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

答案 3 :(得分:0)

在库中制作它们时,您不需要

parent::__construct(); 

更改此

class Pagination_library {

  function __construct() {
    parent::__construct();
    $this->CI =& get_instance();
    $this->CI->load->model('pagination_model');
    $this->CI->load->library('pagination');
  }

  public function orders(){
  }

}

删除parent :: __ construct();

到此

class Pagination_library {

  function __construct() {
    $this->CI =& get_instance();
    $this->CI->load->model('pagination_model');
    $this->CI->load->library('pagination');
  }

  public function orders(){
  }

}