繁体   English   中英

制作可配置的config.php文件

[英]make configurable config.php file

我在更改配置文件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"]);
?>

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

您还可以尝试我写的一个很小的库,即SQLconf以一种更加结构化的方式来管理脚本的配置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM