ComposerでCakePHPをインストールしているとBake実行時にエラーになってしまうようです。
エラー内容
# php ./Console/cake.php bake all posts Welcome to CakePHP v2.4.10 Console --------------------------------------------------------------- App : app Path: /share/Vendor/cakephp/cakephp/app/ --------------------------------------------------------------- Bake All --------------------------------------------------------------- Warning Error: include_once(/share/Vendor/cakephp/cakephp/app/Config/database.php): failed to open stream: No such file or directory in [/share/Vendor/cakephp/cakephp/lib/Cake/Model/ConnectionManager.php, line 67] Warning Error: include_once(): Failed opening '/share/Vendor/cakephp/cakephp/app/Config/database.php' for inclusion (include_path='/share:/share/Vendor/cakephp/cakephp/lib:.:/usr/share/pear:/usr/share/php') in [/share/Vendor/cakephp/cakephp/lib/Cake/Model/ConnectionManager.php, line 67] Error: The datasource configuration "default" was not found in database.php #0 /share/Vendor/cakephp/cakephp/lib/Cake/Model/ConnectionManager.php(91): ConnectionManager::_getConnectionObject('default') #1 /share/Vendor/cakephp/cakephp/lib/Cake/Model/Model.php(3477): ConnectionManager::getDataSource('default') #2 /share/Vendor/cakephp/cakephp/lib/Cake/Model/Model.php(1126): Model->setDataSource('default') #3 /share/Vendor/cakephp/cakephp/lib/Cake/Model/Model.php(3499): Model->setSource('posts') #4 /share/Vendor/cakephp/cakephp/lib/Cake/Model/Model.php(1355): Model->getDataSource() #5 /share/Vendor/cakephp/cakephp/lib/Cake/Console/Command/Task/ModelTask.php(503): Model->schema(true) #6 /share/Vendor/cakephp/cakephp/lib/Cake/Console/Command/Task/ModelTask.php(801): ModelTask->doAssociations(Object(Model)) #7 /share/Vendor/cakephp/cakephp/lib/Cake/Console/Command/BakeShell.php(174): ModelTask->bake(Object(Model), false) #8 /share/Vendor/cakephp/cakephp/lib/Cake/Console/Shell.php(437): BakeShell->all() #9 /share/Vendor/cakephp/cakephp/lib/Cake/Console/ShellDispatcher.php(207): Shell->runCommand('all', Array) #10 /share/Vendor/cakephp/cakephp/lib/Cake/Console/ShellDispatcher.php(66): ShellDispatcher->dispatch() #11 /share/app/Console/cake.php(35): ShellDispatcher::run(Array) #12 {main}
解決策
エラー内容をみると、参照しているプロジェクトのパスが誤っているので、コマンドの引数でプロジェクトのパスを指定してあげたら成功しました。 “–app {プロジェクトのパス}”
# php ./Console/cake.php bake all posts --app /share/app Welcome to CakePHP v2.4.10 Console --------------------------------------------------------------- App : app Path: /share/app/ --------------------------------------------------------------- Bake All --------------------------------------------------------------- Baking model class for posts... Creating file /share/app/Model/posts.php Wrote `/share/app/Model/posts.php` PHPUnit is not installed. Do you want to bake unit test files anyway? (y/n) [y] > y You can download PHPUnit from http://phpunit.de Baking test fixture for CalendarEvent... Creating file /share/app/Test/Fixture/CalendarEventFixture.php Wrote `/share/app/Test/Fixture/CalendarEventFixture.php` Baking test case for CalendarEvent Model ... Creating file /share/app/Test/Case/Model/CalendarEventTest.php Wrote `/share/app/Test/Case/Model/CalendarEventTest.php` You must have a model for this class to build basic methods. Please try again.
コメント