Here is my directory (the screen-shot in this link)另外,我还有一个名为config.php的文件,其中包含一些变量,如:

<?php

    // db
    $dbname = 'mydb';
    $db_username = 'root';
    $db_password = '';

    // login
    $l_email = 'some@one.com';
    $l_password = 'mypas'

    // details
    $sleep_on_error = 1; // per sec

    // and etc
    // .
    // .
    // .

?>

如您所见,我有一些变量存储在config.php文件中。在我的项目的每一部分中,我可能都需要这些变量。所以我需要让config.php文件在整个项目中都可以访问。因此,我可以将config.php文件添加到作曲家中,使其在整个项目中都可以访问。这样地:
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
    },
    "files": [
        "app/classes/config.php"
    ]
},

我所要做的就是为我的项目实现一个简单的配置系统。请告诉我我做得对吗?或者我应该为此定义一个类?或者我所做的一切都是错的,我应该做些别的什么?
简而言之,为项目进行配置的最佳结构是什么?

最佳答案

拉威尔的方法是使用config files。创建my.php并将其放入/config目录,然后全局访问常量值:

config('my.variable')

下面是my.php的一个例子:
<?php

return [
    'variable' => 15,
    'some-array' => [1, 2, 5],
];

10-06 13:24
查看更多