dongnao1908 2014-10-18 13:10
浏览 31

通过前端编辑Codeigniter的配置和数据库设置

I am developing a install script like Magento for a Website, which can be re-used for future projects in CodeIgniter. The purpose of the install script is to create some tables and some basic data for the website such as site name, description, OG tags etc.

There is a prerequisite file say, install-prerequisite.php by which the user will enter the database host, database username, database password and submit the credentials. The prerequisite is excluded from the CodeIgniter's index.php using .htaccess so as to exclude the database connection.

RewriteCond $1 !^(index\.php|install-prerequisite\.php|robots\.txt)

The values from the install-prerequisite.php has to be updated in database.php of the CodeIgniter. This has also to be validated for successful connection too. Is this possible?

Similarly can the config.php be edited by the data from the forms? User can edit the value for sess_cookie_name, sess_expiration etc. from a web page and update to the config.php.

Synoptic:

  1. Update database.php parameters programmatically.
  2. Update config.php parameters programmatically.
  3. Check connection with parameters saved in database.php, from install.php.
  • 写回答

1条回答 默认 最新

  • donglu9898 2014-12-18 20:35
    关注

    I would suggest to store the custom values like database name, user, pass in a Global Database where is accessible by login and not in the file "install-prerequisite.php".

    Then you can load the user's database and config by entering his data and connect manually:

    https://ellislab.com/codeIgniter/user-guide/database/connecting.html https://ellislab.com/codeIgniter/user-guide/libraries/config.html

    by putting this function in the construct of every page or in a pre-controller hook.

    This enables you to edit the configurations without editing phisically the .php file in the config folder (which i think it's bad) and overrides the general config values.

    For example:

    $confvalues = $this->db->where('name','dude')->get('user_configs')->row();
    
    $db['dude']['hostname'] = "localhost";
    $db['dude']['username'] = $confvalues->db_user;
    $db['dude']['password'] = $confvalues->db_pass;
    $active_group = "dude";
    

    Now when you go $this->db it will use the dude's Database

    $this->config->set_item('sess_cookie_name', $confvalues->sess_cookie);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)