From 9f8d8aad0a6926a1e342df8f2e5ebcd149e64e91 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 18 Jan 2024 13:07:51 +0530 Subject: [PATCH 1/2] Improved docs for `fetchModel()` --- en/controllers.rst | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/en/controllers.rst b/en/controllers.rst index 4e252e9775..4eaf686bb7 100644 --- a/en/controllers.rst +++ b/en/controllers.rst @@ -434,22 +434,8 @@ By using the second parameter you can define a status code for your redirect:: See the :ref:`redirect-component-events` section for how to redirect out of a life-cycle handler. -Loading Additional Models -========================= - -.. php:method:: fetchModel(string $alias, array $config = []) - -The ``fetchModel()`` method is useful to load models or ORM tables that -are not the controller's default. Models retrieved with this method will not be -set as properties on your controller:: - - // Get an ElasticSearch model - $articles = $this->fetchModel('Articles', 'Elastic'); - - // Get a webservices model - $github = $this->fetchModel('GitHub', 'Webservice'); - -.. versionadded:: 4.5.0 +Loading Additional Tables/Models +================================ .. php:method:: fetchTable(string $alias, array $config = []) @@ -463,6 +449,25 @@ the controller's default one:: ) ->all(); +.. php:method:: fetchModel(string $alias, array $config = []) + +The ``fetchModel()`` method is useful to load non ORM models or ORM tables that +are not the controller's default:: + + // ModelAwareTrait need to be explicity added to your controler first for fetchModel() to work. + use ModelAwareTrait; + + // Get an ElasticSearch model + $articles = $this->fetchModel('Articles', 'Elastic'); + + // Get a webservices model + $github = $this->fetchModel('GitHub', 'Webservice'); + + // If you skip the 2nd argument it will by default try to load a ORM table. + $authors = $this->fetchModel('Authors'); + +.. versionadded:: 4.5.0 + Paginating a Model ================== From bb8fc0dae1e6c9269997bf5a3fa6970013454ec1 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 18 Jan 2024 19:36:06 +0530 Subject: [PATCH 2/2] Fix method signature --- en/controllers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/en/controllers.rst b/en/controllers.rst index 4eaf686bb7..ea73d1213a 100644 --- a/en/controllers.rst +++ b/en/controllers.rst @@ -449,7 +449,7 @@ the controller's default one:: ) ->all(); -.. php:method:: fetchModel(string $alias, array $config = []) +.. php:method:: fetchModel(string|null $modelClass = null, string|null $modelType = null) The ``fetchModel()`` method is useful to load non ORM models or ORM tables that are not the controller's default::