从数据库读取CodeIgniter配置值,而不是配置文件 [英] Reading CodeIgniter config values from database instead of config file

查看:92
本文介绍了从数据库读取CodeIgniter配置值,而不是配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可能知道,当您使用CI创建新项目时,必须在config / config.php中手动输入基本URL,加密密钥。我想解决这个问题,因此希望能够从数据库 中<读取 这些值。

As you might know, when you create a new project with CI you'll have to manually enter base url, encryption key in config/config.php. I'm trying to overcome this and is hence looking for a way to read those values from a database instead - making the installation for a customer and the set up time as a whole decrease a lot.

客户无法编辑PHP文件的变量,但最常见的是

A customer isn't able to edit a PHP file's variables, but is most likely able to, with some guidance, enter base url and have a encryption key automatically filled in by the system.

有没有办法做到这一点?

Is there any way to accomplish this?

推荐答案

当然!添加 hook-post_controller 并通过该文件设置这些配置值。

Of course! Add a hook - post_controller and set these config values through that file.

config / hooks.php

$hook['pre_controller'][] = array(  'class'    => 'MyOtherClass',
                                    'function' => 'MyOtherfunction',
                                    'filename' => 'Myotherclass.php',
                                    'filepath' => 'hooks');

hooks / myotherclass.php

<?

class MyOtherClass {

    function MyOtherfunction() {

        $CI =& get_instance();

        $row = $CI->db->get_where('configs', array('site_id' => 1))->row();

        $CI->config->set_item('base_url', $row->base_url);

    }

}

这些值在用于任何控制器或类似操作之前。

Basicly you set these values before they're used in any controller or similiar.

这篇关于从数据库读取CodeIgniter配置值,而不是配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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