制作可配置的config.php文件

时间:2010-07-27 13:49:04

标签: php configuration

我在更改配置文件config.php时遇到问题。目前,我正在尝试通过驻留在同一目录中的表单来配置数据库详细信息$config['db],但是,当我包含配置文件时,不会实现通道。这是config.php的样子:

<?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 个答案:

答案 0 :(得分:1)

没有代码可以更改config.php文件本身,这可能就是问题所在。通常问题是配置文件的权限 - 如果它是服务器可配置的(使用表单或其他方式),则文件的权限必须允许它。

您还可以尝试使用我写回来的小型库来更有条理地管理脚本配置 - SQLconf