File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -559,6 +559,36 @@ $recentArticles = $this->fetchTable('Articles')->find('all',
559559)->all();
560560```
561561
562+ ### The defaultTable Property
563+
564+ By convention, controllers are associated with a primary model table. For
565+ example, ` PostsController ` will have ` Posts ` as its default table. You can
566+ customize this by setting the ` $defaultTable ` property:
567+
568+ ``` php
569+ class PostsController extends AppController
570+ {
571+ // Use Comments as the default table instead of Posts.
572+ protected ?string $defaultTable = 'Comments';
573+ }
574+ ```
575+
576+ When ` $defaultTable ` is set, calling ` fetchTable() ` without arguments will
577+ return that table. If your controller doesn't use a table, you can set
578+ ` $defaultTable ` to an empty string:
579+
580+ ``` php
581+ class DashboardController extends AppController
582+ {
583+ // This controller doesn't use a table.
584+ protected ?string $defaultTable = '';
585+ }
586+ ```
587+
588+ Setting ` $defaultTable ` to an empty string also prevents potential naming
589+ conflicts when loading components that share the same alias as the default
590+ table name.
591+
562592### fetchModel()
563593
564594` method ` Cake\\ Controller\\ Controller::** fetchModel** (?string $modelClass = null, ?string $modelType = null): object
You can’t perform that action at this time.
0 commit comments