douyi5822 2010-07-27 13:49
浏览 55
已采纳

制作可配置的config.php文件

I'm having problems with changing my configuration file config.php. At the moment, I'm trying to configure the databse details $config['db] through a form residing in the same directory, however, when I include the configuration file the channges do not materialise. Here's what config.php looks like:

<?php
//main path to resources
$resources = dirname(__DIR__);
//$root = dirname(dirname(__DIR__));
$root = dirname($resources);


//configuration array to hold
//vital information
$config = array(
    "db" => array(
            "username" => null,
            "password" => null,
            "host" => null,
            "database" => null
    ),
    "directories" => array(
            "document_root" => $root,
            "site_root" => $root . '/public_html',
            "resources" => $resources,
            "templates" => $resources . '/templates',
            "library" => $resources . '/library',
            "views" => $resources . '/views',
            "controllers" => $resources . '/controllers',
            "backups" => $resources . '/backups',
            "admin" => $resources . '/admin'
    ),
    "pages" => array(
        "index" => array(
            "title" => "Welcome, you can order your tickets to St. Tom's
                Ambulance annual ball here",
            "headers" => array("introduction", "the process", "start"),
            "views" => array("/index.form.view.php", "/index.data.view.php",
                "/index.side.view.php")
        ),
        "login" => array(
            "title" => "Log in here so as to place your order.",
            "headers" => array("log in", "guests' details", "choose seats"),
            "views" => array("/login.view.php", "/guests.view.php",
                "/table.select.order.view.php")
        ),
        "amend" => array(
            "title" => "Amend your order here.",
            "headers" => array("enter order no.", "available seats",
                "amend seats"),
            "views" => array("/amend.view.form.php",
                "/table.select.amend.view.php", "/amend.view.side.php")
        ),
        "menus" => array(
            "title" => "Select your menus and checkout here.",
            "headers" => array("view menus", "select menus",
                "check out"),
            "views" => array("/menus.see.view.php",
                "/menus.select.view.php", "/checkout.view.php")
        ),
        "message" => array(
            "title" => "Information about your order."
        ),
        "amend_message" => array(
            "title" => "Information about your ammendment."
        )
    ),
    "month" => array("January", "February", "March", "April", "May", "June",
        "July", "August", "September", "October", "November", "December"),
    "ticket_price" => 30,
    "year_limit" => (2010 - 13),
    "event_dateTime" => '2010-11-20 19:00:00'
);

require_once($config['directories']['library']. "/class/FormDB.php");


$form = new FormDB($config["db"]["host"],
    $config["db"]["username"],
    $config["db"]["password"],
    $config["db"]["database"],
    $config["event_dateTime"]);
?>
  • 写回答

1条回答 默认 最新

  • doubiao9775 2010-07-27 14:04
    关注

    There's no code to change the config.php file itself, and that's probably where the problem lies. Often the issue is the permissions of the configuration file - if it is to be server-configurable (with forms or otherwise), the permissions on the file must allow it.

    You can also try a tiny library I wrote way back to manage the configuration of scripts in a more structured way - SQLconf.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多