How to change data in custom loaded config array

不羁的心 提交于 2020-01-07 03:10:08

问题


I'm doing pagination using Codeigniter pagination class. My current config variable is:

$config['base_url'] = base_url('admin/sub_categories');
$config['total_rows'] = $this->sub_categories_model->get_count();
$config['base_url'] = "";
$config['total_rows'] = "";
$config['per_page'] = 30;
$config['first_link'] = 'Эхнийх';
$config['last_link'] = 'Сүүлийх';
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '&laquo';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&raquo';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_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>';

Then using it on every controller was using too many lines. So I created pagination.php under config/ folder. Then put above codes. Then loaded it like:

$this->config->load('pagination', TRUE);
$this->pagination->initialize($this->config->item('pagination'));

Now you see, my problem is $config['base_url'] and $config['total_rows'] can be different on every controllers. How can I change their value after load?


回答1:


If I understand you, then you may try this:

$this->config->load('pagination', TRUE);
$conf = $this->config->item('pagination');
$conf['base_url'] = base_url('admin/sub_categories');
$conf['total_rows'] = $this->sub_categories_model->get_count();
$this->pagination->initialize($conf);

You should do it at every controller you want to use paginator with diferent values for base_url and total_rows



来源:https://stackoverflow.com/questions/34706828/how-to-change-data-in-custom-loaded-config-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!