Laravel从错误的目录中提取数据库设置

时间:2014-04-19 21:20:50

标签: php laravel laravel-4

我创建了app/config/mysite.dev并在此目录中添加了app.phpdatabase.php。然后,我将bootstrap/start.php中的本地,登台和制作的值更改为引用mysite.dev。但是,不是检查app/config/mysite.dev/database.php设置,而是阅读app/config/database.php

我觉得我错过了一些重要的步骤。

有什么想法吗?

这是我的bootstrap/start.php文件:

<?php

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/

$app = new Illuminate\Foundation\Application;

/*
|--------------------------------------------------------------------------
| Detect The Application Environment
|--------------------------------------------------------------------------
|
| Laravel takes a dead simple approach to your application environments
| so you can just specify a machine name or HTTP host that matches a
| given environment, then we will automatically detect it for you.
|
*/

$env = $app->detectEnvironment(array(

    'local' => array('mysite.dev'), // Change this to your local machine hostname.
    'staging' => array('mysite.dev'),
    'production' => array('mysite.dev'),

));

/*
|--------------------------------------------------------------------------
| Bind Paths
|--------------------------------------------------------------------------
|
| Here we are binding the paths configured in paths.php to the app. You
| should not be changing these here. If you need to change these you
| may do so within the paths.php file and they will be bound here.
|
*/

$app->bindInstallPaths(require __DIR__.'/paths.php');

/*
|--------------------------------------------------------------------------
| Load The Application
|--------------------------------------------------------------------------
|
| Here we will load the Illuminate application. We'll keep this is in a
| separate location so we can isolate the creation of an application
| from the actual running of the application with a given request.
|
*/

$framework = $app['path.base'].'/vendor/laravel/framework/src';

require $framework.'/Illuminate/Foundation/start.php';

/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/

return $app;

1 个答案:

答案 0 :(得分:1)

如果你确定你的主机名是'mysite.dev'并且你已将数据库配置放在app/config/mysite.dev/database.php中,那么你需要以下$app->detectEnvironment

$env = $app->detectEnvironment(array(

    'mysite.dev' => array('mysite.dev')

));

我建议将app/config/mysite.dev/database.php重命名为app/config/dev/database.php,然后执行以下操作:

$env = $app->detectEnvironment(array(

    'dev' => array('mysite.dev')

));

如评论中所述:数组中的键对应于文件夹名称,而值是包含计算机主机名的数组。