CodeIgniter - accessing $config variable in view

后端 未结 11 1044
青春惊慌失措
青春惊慌失措 2020-12-23 12:52

Pretty often I need to access $config variables in views. I know I can pass them from controller to load->view(). But it seems excessive to do i

相关标签:
11条回答
  • 2020-12-23 13:24

    You can do something like that:

    $ci = get_instance(); // CI_Loader instance
    $ci->load->config('email');
    echo $ci->config->item('name');
    
    0 讨论(0)
  • 2020-12-23 13:25

    $config['cricket'] = 'bat'; in config.php file

    $this->config->item('cricket') use this in view

    0 讨论(0)
  • 2020-12-23 13:26

    $this->config->item() works fine.

    For example, if the config file contains $config['foo'] = 'bar'; then $this->config->item('foo') == 'bar'

    0 讨论(0)
  • 2020-12-23 13:38

    $this->config->item('config_var') did not work for my case.

    I could only use the config_item('config_var'); to echo variables in the view

    0 讨论(0)
  • 2020-12-23 13:38

    This is how I did it. In config.php

    $config['HTML_TITLE'] = "SO TITLE test";
    

    In applications/view/header.php (assuming html code)

    <title><?=$this->config->item("HTML_TITLE");?> </title>
    

    0 讨论(0)
  • 2020-12-23 13:40

    Whenever I need to access config variables I tend to use: $this->config->config['variable_name'];

    0 讨论(0)
提交回复
热议问题