CakePHP - 蛋糕烘焙全部错误(说 database.php 中缺少 $default,但它存在)

CakePHP - cake bake all error (says missing $default in database.php, but it is present)

我正在尝试用 cake bake all 来烘烤所有东西,但是 returns 出现各种错误。它说找不到 database.php 中的默认值,但实际上它存在于文件中,而且,几天前我烘焙了几个模型等,并且工作正常。这是输出:

C:\wamp64\www\WarehouseManagementApp\app\Console>cake bake all

Warning Error: Use of undefined constant TESTS - assumed ‘TESTS’ (this will throw an Error in a future version of PHP) in [C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\TaskCollection.php, line 94]
Welcome to CakePHP v2.10.19 Console
App : Console
Path: C:\wamp64\www\WarehouseManagementApp\app\Console\
Bake All

Warning Error: include_once(C:\wamp64\www\WarehouseManagementApp\app\Console\Config\database.php): failed to open stream: No such file or directory in [C:\wamp64\www\WarehouseManagementApp\lib\Cake\Model\ConnectionManager.php, line 67]

Warning Error: include_once(): Failed opening ‘C:\wamp64\www\WarehouseManagementApp\app\Console\Config\database.php’ for inclusion (include_path=‘C:\wamp64\www\WarehouseManagementApp\lib;.;C:\php\pear’) in [C:\wamp64\www\WarehouseManagementApp\lib\Cake\Model\ConnectionManager.php, line 67]

Error: The datasource configuration “default” was not found in database.php
#0 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Model\ConnectionManager.php(91): ConnectionManager::_getConnectionObject(‘default’)
#1 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Command\Task\ModelTask.php(956): ConnectionManager::getDataSource(‘default’)
#2 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Command\Task\ModelTask.php(893): ModelTask->getAllTables(‘default’)
#3 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Command\Task\ModelTask.php(983): ModelTask->listAll(‘default’)
#4 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Command\BakeShell.php(150): ModelTask->getName(‘default’)
#5 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Shell.php(459): BakeShell->all()
#6 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\ShellDispatcher.php(222): Shell->runCommand(‘all’, Array)
#7 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\ShellDispatcher.php(66): ShellDispatcher->dispatch()
#8 C:\wamp64\www\WarehouseManagementApp\app\Console\cake.php(47): ShellDispatcher::run(Array)
#9 {main}

此外,这是我的 database.php 文件:

class DATABASE_CONFIG {

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'root',
    'password' => '',
    'database' => 'modules',
    'prefix' => '',

// ‘encoding’ => ‘utf8’,
);

public $test = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'user',
    'password' => 'password',
    'database' => 'test_database_name',
    'prefix' => '',
    //'encoding' => 'utf8',
);

}

查看包含错误,它们告诉您无法找到您的 database.php 文件,如果您查看路径,您会发现它在 Console/Config 文件夹中,即当然位置不对。

这是因为 shell 将使用当前工作目录作为应用程序路径,所以 运行 您 app 文件夹中的控制台,即 Console\cake bake all ,或使用 -app 参数将路径传递到您的 app 文件夹:

cake bake all -app "C:\wamp64\www\WarehouseManagementApp\app"

蛋糕 shell 也告诉了你 (cake --help),并向你展示了相关路径。

另见