@@ -434,48 +434,39 @@ By using the second parameter you can define a status code for your redirect::
434434See the :ref: `redirect-component-events ` section for how to redirect out of
435435a life-cycle handler.
436436
437- Forwarding to an Action on the Same Controller
438- ----------------------------------------------
437+ Loading Additional Tables/Models
438+ ================================
439439
440- .. php :method :: setAction($action, $args... )
440+ .. php :method :: fetchTable(string $alias, array $config = [] )
441441
442- If you need to forward the current action to a different action on the *same *
443- controller, you can use ``Controller::setAction() `` to update the request
444- object, modify the view template that will be rendered and forward execution to
445- the named action::
442+ The ``fetchTable() `` method comes handy when you need to use an ORM table that is not
443+ the controller's default one::
446444
447- // From a delete action, you can render the updated
448- // list page.
449- $this->setAction('index');
445+ // In a controller method.
446+ $recentArticles = $this->fetchTable('Articles')->find('all',
447+ limit: 5,
448+ order: 'Articles.created DESC'
449+ )
450+ ->all();
450451
451- Loading Additional Models
452- =========================
452+ .. php :method :: fetchModel(string|null $modelClass = null, string|null $modelType = null)
453453
454- .. php :method :: fetchModel(string $alias, array $config = [])
454+ The ``fetchModel() `` method is useful to load non ORM models or ORM tables that
455+ are not the controller's default::
455456
456- The ``fetchModel() `` method is useful to load models or ORM tables that
457- are not the controller's default. Models retrieved with this method will not be
458- set as properties on your controller::
457+ // ModelAwareTrait need to be explicity added to your controler first for fetchModel() to work.
458+ use ModelAwareTrait;
459459
460460 // Get an ElasticSearch model
461461 $articles = $this->fetchModel('Articles', 'Elastic');
462462
463463 // Get a webservices model
464464 $github = $this->fetchModel('GitHub', 'Webservice');
465465
466- .. versionadded :: 4.5.0
467-
468- .. php :method :: fetchTable(string $alias, array $config = [])
469-
470- The ``fetchTable() `` method comes handy when you need to use an ORM table that is not
471- the controller's default one::
466+ // If you skip the 2nd argument it will by default try to load a ORM table.
467+ $authors = $this->fetchModel('Authors');
472468
473- // In a controller method.
474- $recentArticles = $this->fetchTable('Articles')->find('all',
475- limit: 5,
476- order: 'Articles.created DESC'
477- )
478- ->all();
469+ .. versionadded :: 4.5.0
479470
480471Paginating a Model
481472==================
0 commit comments