2015-07-21 53 views
1

我在嘗試執行cake bake all,但不起作用,因爲我認爲問題出在我的蛋糕項目的路徑上。當我嘗試執行終端上的命令時會拋出以下異常:Error: The datasource configuration "default" was not found in database.php。文件database.php在這個路徑ExemploCake/app/Config/database.phpUbuntu + Lampp和CakePHP?

我使用的是:Ubuntu的使用LAMPP和CakePHP 2.7

配置爲database.php

<?php 
class DATABASE_CONFIG { 

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

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

異常從app文件夾

[email protected]:/opt/lampp/htdocs/ExemploCake/app/Console# ./cake bake all 

Welcome to CakePHP v2.7.0 Console 
--------------------------------------------------------------- 
App : app 
Path: /opt/lampp/htdocs/ExemploCake/app/ 
--------------------------------------------------------------- 
Bake All 
--------------------------------------------------------------- 
Error: Database connection "Mysql" is missing, or could not be created. 
#0 /opt/lampp/htdocs/ExemploCake/lib/Cake/Model/ConnectionManager.php(105): DboSource->__construct(Array) 
#1 /opt/lampp/htdocs/ExemploCake/lib/Cake/Console/Command/Task/ModelTask.php(952): ConnectionManager::getDataSource('default') 
#2 /opt/lampp/htdocs/ExemploCake/lib/Cake/Console/Command/Task/ModelTask.php(889): ModelTask->getAllTables('default') 
#3 /opt/lampp/htdocs/ExemploCake/lib/Cake/Console/Command/Task/ModelTask.php(979): ModelTask->listAll('default') 
#4 /opt/lampp/htdocs/ExemploCake/lib/Cake/Console/Command/BakeShell.php(150): ModelTask->getName('default') 
#5 /opt/lampp/htdocs/ExemploCake/lib/Cake/Console/Shell.php(444): BakeShell->all() 
#6 /opt/lampp/htdocs/ExemploCake/lib/Cake/Console/ShellDispatcher.php(212): Shell->runCommand('all', Array) 
#7 /opt/lampp/htdocs/ExemploCake/lib/Cake/Console/ShellDispatcher.php(66): ShellDispatcher->dispatch() 
#8 /opt/lampp/htdocs/ExemploCake/app/Console/cake.php(47): ShellDispatcher::run(Array) 
#9 {main} 
+0

在ubuntu上安裝mysql的最新版本 –

回答

0

運行bake。所以:

cd /opt/lampp/htdocs/ExemploCake/app 
./Console/cake bake all 

編輯基於更新的帖子:

的錯誤意味着你不必爲CLI啓用PDO_MYSQL。因此找出CLI的php.ini並啓用它。

看來你正在使用XAMPP。如果你只是使用我自己的Ubuntu提供的軟件包,你將節省很多麻煩。你會在網上找到大量的教程。

+0

我編輯了帖子。如果我從我的應用程序文件夾運行'bake'會引發以下異常:'錯誤:數據庫連接「Mysql」丟失或無法創建。但在瀏覽器中一切正常,請查看:http://i.imgur。 COM/fx7CJBi.png – FernandoPaiva