如何更改自定义加载的配置数组中的数据 [英] How to change data in custom loaded config array

查看:85
本文介绍了如何更改自定义加载的配置数组中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Codeigniter分页类进行分页。我当前的配置变量是:

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>';

然后在每个控制器上使用太多行。所以我在config /文件夹下创建了pagination.php。然后放上面的代码。然后加载它像:

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'));

现在你看到了,我的问题是 $ config ['base_url'] $ config ['total_rows'] 可以在每个控制器上不同。

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?

推荐答案

如果我理解你,那么你可以尝试:

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

您应该在每个控制器上使用 paginator 与不同的值 base_url total_rows

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

这篇关于如何更改自定义加载的配置数组中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆