gpt4 book ai didi

arrays - Codeigniter:如何使用 Controller 访问配置文件中的多维数组?

转载 作者:行者123 更新时间:2023-12-04 02:50:54 25 4
gpt4 key购买 nike

为什么这不起作用?请帮助我!

我的 Controller 代码:

class frontend_controller extends CI_Controller {

private $values;

public function get_config() {

parent::__construct();


$CI = &get_instance(); //assigned the object to a variable
$CI->config->load('example_config', TRUE); // get config file

// get all config values
$this->values = $CI->config->item('example_config',['frontend1']);

$this->load->library('session');
}



}

模板渲染 Controller :

require_once('frontend_controller.php'); 
class frontend1_controller extends frontend_controller {


public function __construct() {
parent::__construct();
}


function template() {



$this->load->view('template', $this->get_config());
}

}

配置文件:

$config['frontend1']['base_url'] = "http://www.test.com/";
$config['frontend1']['login_error_url'] = "www.test.com/login_failed";
$config['frontend1']['login_success_url'] = "www.test.com/login_success";
$config['frontend1']['js'] = "www.test.com/js/file.js";
$config['frontend1']['css'] = "www.test.com/css/style.css";
$config['frontend1']['my_title'] = ' Test123' ;
$config['frontend2']['base_url'] = "www.test.com";
$config['frontend2']['login_error_url'] = "http://www.test.com/login_failed";
$config['frontend2']['login_success_url'] = "http://www.test.com/login_success";
$config['frontend2']['js'] = "http://www.test.com/js/file.js";
$config['frontend2']['css'] = "http://www.test.com/css/style.css";
$config['frontend2']['my_title'] = ' Test123' ;

在模板中:

<p><?php echo $base_url ?></p>

我想读入配置文件,但只读 frontend1-arrays。我该怎么做?

最佳答案

请不要写括号;

$this->values = $CI->config->item('example_config', 'frontend1');

关于arrays - Codeigniter:如何使用 Controller 访问配置文件中的多维数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17781356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com