简体   繁体   中英

CakePHP v3.x how to bake without database connection

I'm using CakePHP v3.x and my app doesn't have any models but I'd like to back a couple views or controllers.

$ bin/cake bake template Reports

I tried: * using the --connection option with false or an empty string * Removing Datasources from app.php * Leaving in Datasources but set Datasources['default'] to false

All of these result in an error:

Welcome to CakePHP v3.1.2 Console
---------------------------------------------------------------
App : src
Path: /Applications/MAMP/htdocs/listings/src/
PHP : 5.6.10
---------------------------------------------------------------
Exception: The datasource configuration "default" was not found. in [/Applications/MAMP/htdocs/listings/vendor/cakephp/cakephp/src/Datasource/ConnectionManager.php, line 187]
2015-10-22 02:30:48 Error: [Cake\Datasource\Exception\MissingDatasourceConfigException] The datasource configuration "default" was not found.
Exception Attributes: array (
  'name' => 'default',
)
Stack Trace:
#0 /Applications/MAMP/htdocs/listings/vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php(164): Cake\Datasource\ConnectionManager::get('default')
#1 /Applications/MAMP/htdocs/listings/vendor/cakephp/cakephp/src/ORM/TableRegistry.php(109): Cake\ORM\Locator\TableLocator->get('Reports', Array)
#2 /Applications/MAMP/htdocs/listings/vendor/cakephp/bake/src/Shell/Task/TemplateTask.php(282): Cake\ORM\TableRegistry::get('Reports')
#3 /Applications/MAMP/htdocs/listings/vendor/cakephp/bake/src/Shell/Task/TemplateTask.php(147): Bake\Shell\Task\TemplateTask->_loadController()
#4 [internal function]: Bake\Shell\Task\TemplateTask->main('Reports')
#5 /Applications/MAMP/htdocs/listings/vendor/cakephp/cakephp/src/Console/Shell.php(447): call_user_func_array(Array, Array)
#6 /Applications/MAMP/htdocs/listings/vendor/cakephp/cakephp/src/Console/Shell.php(442): Cake\Console\Shell->runCommand(Array, false)
#7 /Applications/MAMP/htdocs/listings/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(212): Cake\Console\Shell->runCommand(Array, true, Array)
#8 /Applications/MAMP/htdocs/listings/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(179): Cake\Console\ShellDispatcher->_dispatch(Array)
#9 /Applications/MAMP/htdocs/listings/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(126): Cake\Console\ShellDispatcher->dispatch(Array)
#10 /Applications/MAMP/htdocs/listings/bin/cake.php(33): Cake\Console\ShellDispatcher::run(Array)
#11 {main}

I doubt this will work any time soon. You can create feature request type ticket on Github but it's unlikely to happen, because bake uses the DB schema to read the fields and builds everything based on the schema.

Also the Table class, which replaced Model from Cake2, doesn't allow $useTable = false any more. Because a table requires a DB table. For model less forms see this link .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM