Skip to content

Commit d3d710e

Browse files
authored
Merge pull request #7881 from cakephp/disable-auto-tables
Update info for disabling "auto-tables"
2 parents a51255a + 9daf110 commit d3d710e

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

en/development/application.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ global event listeners::
6363
// Call the parent to `require_once` config/bootstrap.php
6464
parent::bootstrap();
6565

66+
// CakePHP has the ability to fallback to using the `Cake\ORM\Table`
67+
// class to represent your database tables when a related class is
68+
// not created for that table. But using this "auto-tables" feature
69+
// can make debugging more difficult in some scenarios. So we disable
70+
// this feature except for the CLI environment (since the classes
71+
// would not be present when using the `bake` code generation tool).
72+
if (PHP_SAPI !== 'cli') {
73+
FactoryLocator::add(
74+
'Table',
75+
(new TableLocator())->allowFallbackClass(false)
76+
);
77+
}
78+
6679
// Load MyPlugin
6780
$this->addPlugin('MyPlugin');
6881
}
@@ -74,4 +87,4 @@ each test method.
7487

7588
.. meta::
7689
:title lang=en: CakePHP Application
77-
:keywords lang=en: http, middleware, psr-7, events, plugins, application, baseapplication
90+
:keywords lang=en: http, middleware, psr-7, events, plugins, application, baseapplication,auto tables,auto-tables,generic table,class

en/development/configuration.rst

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -564,36 +564,6 @@ The built in configuration engines are:
564564

565565
By default your application will use ``PhpConfig``.
566566

567-
Disabling Generic Tables
568-
========================
569-
570-
While utilizing generic table classes - also called auto-tables - when quickly
571-
creating new applications and baking models is useful, generic table class can
572-
make debugging more difficult in some scenarios.
573-
574-
You can check if any query was emitted from a generic table class via DebugKit
575-
via the SQL panel in DebugKit. If you're still having trouble diagnosing an
576-
issue that could be caused by auto-tables, you can throw an exception when
577-
CakePHP implicitly uses a generic ``Cake\ORM\Table`` instead of your concrete
578-
class like so::
579-
580-
// In your bootstrap.php
581-
use Cake\Event\EventManager;
582-
use Cake\Http\Exception\InternalErrorException;
583-
584-
$isCakeBakeShellRunning = (PHP_SAPI === 'cli' && isset($argv[1]) && $argv[1] === 'bake');
585-
if (!$isCakeBakeShellRunning) {
586-
EventManager::instance()->on('Model.initialize', function($event) {
587-
$subject = $event->getSubject();
588-
if (get_class($subject) === 'Cake\ORM\Table') {
589-
$msg = sprintf(
590-
'Missing table class or incorrect alias when registering table class for database table %s.',
591-
$subject->getTable());
592-
throw new InternalErrorException($msg);
593-
}
594-
});
595-
}
596-
597567
.. meta::
598568
:title lang=en: Configuration
599-
:keywords lang=en: finished configuration,legacy database,database configuration,value pairs,default connection,optional configuration,example database,php class,configuration database,default database,configuration steps,index database,configuration details,class database,host localhost,inflections,key value,database connection,piece of cake,basic web,auto tables,auto-tables,generic table,class
569+
:keywords lang=en: finished configuration,legacy database,database configuration,value pairs,default connection,optional configuration,example database,php class,configuration database,default database,configuration steps,index database,configuration details,class database,host localhost,inflections,key value,database connection,piece of cake,basic web

0 commit comments

Comments
 (0)