CodeIgniter - 在视图中访问$ config变量

Ale*_*exA 97 php codeigniter

我经常需要访问$config视图中的变量.我知道我可以将它们从控制器传递给load->view().但明确地做这件事似乎过分了.

是否有一些方法或技巧可以$config从CI视图访问变量而不会打扰带有备用代码的控制器?

Phi*_*eon 190

$this->config->item() 工作良好.

例如,如果配置文件包含$config['foo'] = 'bar';然后$this->config->item('foo') == 'bar'


Phi*_*eon 27

此外,Common函数config_item()在整个CodeIgniter实例中几乎无处不在.控制器,模型,视图,库,助手,钩子,等等.


Ale*_*ein 15

你可以这样做:

$ci = get_instance(); // CI_Loader instance
$ci->load->config('email');
echo $ci->config->item('name');
Run Code Online (Sandbox Code Playgroud)

  • Actualy在视图中$ this指的是CI_Loader,get_instance()指的是CI_Base(). (3认同)

小智 8

$this->config->item('config_var') 不适合我的情况.

我只能config_item('config_var');在视图中使用回显变量