我是这样的控制者
function view()
{
if($this->tank_auth->get_user_role_id() == 1){
$users = null;
}else{
$users = $this->_get_users_id();
}
//count total rows of transaction list
$this->db->where('user_id',$users);
$this->db->from('book_packages');
$config['base_url'] = base_url().'index.php/transaction/view';
$config['total_rows'] = $this->db->count_all_results();
$config['per_page'] = 10;
$config['uri_segment'] = 3;
$config['num_links'] = 1;
/* this is config tag */
$this->pagination->initialize($config);
$data['total_rows'] = $config['total_rows'] ;
$data['title'] = 'List transaction';
$data['text'] = $this->transaction_model->view_transaction($config['per_page'],$this->uri->segment(3),$users);
$data['pagecontent'] = "admin/view_transaction";
$this->load->vars($data);
$this->load->view('template');
}
我在视图$this->pagination->create_links();
中回应了这一点
当我加载控制器时,我得到了像这样的错误
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Transaction::$pagination
Filename: controllers/transaction.php
Line Number: 804
Fatal error: Call to a member function initialize() on a non-object in my directory
我不知道为什么,我已经加载了图书馆分页,帮助网址,带有资本的班级名称。 当我将代码上传到托管时,它就会发生,但是当我在localhost中加载它时,我没有收到任何错误。
任何帮助都非常感谢。 非常感谢你。
答案 0 :(得分:2)
function view()
{
if($this->tank_auth->get_user_role_id() == 1){
$users = null;
}else{
$users = $this->_get_users_id();
}
//count total rows of transaction list
$this->db->where('user_id',$users);
$this->db->from('book_packages');
$config['base_url'] = base_url().'index.php/transaction/view';
$config['total_rows'] = $this->db->count_all_results();
$config['per_page'] = 10;
$config['uri_segment'] = 3;
$config['num_links'] = 1;
/* this is config tag */
/*THIS IS MISSING*/
$this->load->library('pagination');
$this->pagination->initialize($config);
$data['total_rows'] = $config['total_rows'] ;
$data['title'] = 'List transaction';
$data['text'] = $this->transaction_model->view_transaction($config['per_page'],$this->uri->segment(3),$users);
$data['pagecontent'] = "admin/view_transaction";
$this->load->vars($data);
$this->load->view('template');
}
答案 1 :(得分:0)
错误消息表明$this->pagination
未定义。您在哪里定义(比方说)$this->pagination = new Pagination()
?显然,new Pagination
必须由您的分页库的名称替换。
答案 2 :(得分:0)
尝试将自动加载脚本放在控制器开头的_construct()上。
必须是这样的:
public function __construct(){
parent:: __construct();
$this->load->library("pagination");
}
然后在你的方法上,首先尝试初始化你的$ config:
$ config = array();
$ config [' base_url'] = base_url()。' index.php / transaction / view';
$ config [' total_rows'] = $ this-> db-> count_all_results();
$ config [' per_page'] = 10;
$ config [' uri_segment'] = 3;
$ config [' num_links'] = 1;
或者,如果您确实包含了“分页”,请再次检查config / autoload.php下的自动加载文件。在$ autoload [' libraries']