From e10c5fda1e426557e1a0da6cf7341261a09e4689 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Thu, 4 Apr 2019 22:32:34 -0400 Subject: [PATCH 1/2] Cleanup 4.x docs more * Fix element directory name. * Fix formatting. * Fix link names. --- en/controllers.rst | 4 +- en/controllers/components.rst | 12 ++---- en/controllers/components/flash.rst | 10 ++--- en/debug-kit.rst | 2 +- en/development/sessions.rst | 12 +++--- en/views.rst | 4 +- en/views/helpers/flash.rst | 6 +-- en/views/helpers/form.rst | 7 ++-- en/views/helpers/html.rst | 61 ----------------------------- en/views/json-and-xml-views.rst | 6 --- 10 files changed, 27 insertions(+), 97 deletions(-) diff --git a/en/controllers.rst b/en/controllers.rst index e96ee0493d..3915b33aa9 100644 --- a/en/controllers.rst +++ b/en/controllers.rst @@ -244,8 +244,8 @@ If ``$view`` starts with '/', it is assumed to be a view or element file relative to the **templates** folder. This allows direct rendering of elements, very useful in AJAX calls:: - // Render the element in templates/Element/ajaxreturn.php - $this->render('/Element/ajaxreturn'); + // Render the element in templates/element/ajaxreturn.php + $this->render('/element/ajaxreturn'); The second parameter ``$layout`` of ``Controller::render()`` allows you to specify the layout with which the view is rendered. diff --git a/en/controllers/components.rst b/en/controllers/components.rst index 8e53c0d213..883db005ed 100644 --- a/en/controllers/components.rst +++ b/en/controllers/components.rst @@ -37,9 +37,8 @@ Controller's ``initialize()`` method or via the ``$components`` array:: public function initialize(): void { parent::initialize(); - $this->loadComponent('Auth', [ - 'authorize' => 'Controller', - 'loginAction' => ['controller' => 'Users', 'action' => 'login'] + $this->loadComponent('RequestHandler', [ + 'viewClassMap' => ['json' => 'AppJsonView'], ]); $this->loadComponent('Security', ['blackholeCallback' => 'blackhole']); } @@ -52,17 +51,14 @@ also be expressed as:: public function beforeFilter(EventInterface $event) { - $this->Auth->config('authorize', ['controller']); - $this->Auth->config('loginAction', ['controller' => 'Users', 'action' => 'login']); - - $this->Cookie->config('name', 'CookieMonster'); + $this->RequestHandler->config('viewClassMap', ['rss' => 'MyRssView']); } Like helpers, components implement a ``config()`` method that is used to get and set any configuration data for a component:: // Read config data. - $this->Auth->config('loginAction'); + $this->RequestHandler->config('viewClassMap'); // Set config $this->Csrf->config('cookieName', 'token'); diff --git a/en/controllers/components/flash.rst b/en/controllers/components/flash.rst index 339ae74414..f886083dc6 100644 --- a/en/controllers/components/flash.rst +++ b/en/controllers/components/flash.rst @@ -17,14 +17,14 @@ Setting Flash Messages FlashComponent provides two ways to set flash messages: its ``__call()`` magic method and its ``set()`` method. To furnish your application with verbosity, FlashComponent's ``__call()`` magic method allows you use a method name that -maps to an element located under the **templates/Element/Flash** directory. +maps to an element located under the **templates/element/Flash** directory. By convention, camelcased methods will map to the lowercased and underscored element name:: - // Uses templates/Element/Flash/success.php + // Uses templates/element/Flash/success.php $this->Flash->success('This was successful'); - // Uses templates/Element/Flash/great_success.php + // Uses templates/element/Flash/great_success.php $this->Flash->greatSuccess('This was greatly successful'); Alternatively, to set a plain-text message without rendering an element, you can @@ -64,7 +64,7 @@ An example of using these options:: // In your View Flash->render('positive') ?> - +
: , .
@@ -77,7 +77,7 @@ set the ``plugin`` parameter. For example:: $this->Flash->warning('My message', ['plugin' => 'PluginName']); The code above will use the **warning.php** element under -**plugins/PluginName/templates/Element/Flash** for rendering the flash +**plugins/PluginName/templates/element/Flash** for rendering the flash message. .. note:: diff --git a/en/debug-kit.rst b/en/debug-kit.rst index aa142d1695..1ab72b544e 100644 --- a/en/debug-kit.rst +++ b/en/debug-kit.rst @@ -222,7 +222,7 @@ Each Panel is expected to have a view element that renders the content from the panel. The element name must be the underscored inflection of the class name. For example ``SessionPanel`` has an element named **session_panel.php**, and SqllogPanel has an element named **sqllog_panel.php**. These elements should be -located in the root of your **templates/Element** directory. +located in the root of your **templates/element** directory. Custom Titles and Elements -------------------------- diff --git a/en/development/sessions.rst b/en/development/sessions.rst index f1a53f4a98..58174d6061 100644 --- a/en/development/sessions.rst +++ b/en/development/sessions.rst @@ -12,7 +12,7 @@ avoided in CakePHP, and instead usage of the Session classes is preferred. Session Configuration ===================== -Session configuration is generally defined in ``/config/app.php``. The available +Session configuration is generally defined in **/config/app.php**. The available options are: * ``Session.timeout`` - The number of *minutes* before CakePHP's session @@ -164,7 +164,7 @@ This configuration requires a database table, having this schema:: PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -You can find a copy of the schema for the sessions table in the `application skeleton `_ in ``config/schema/sessions.sql``. +You can find a copy of the schema for the sessions table in the `application skeleton `_ in **config/schema/sessions.sql**. You can also use your own ``Table`` class to handle the saving of the sessions:: @@ -284,8 +284,8 @@ Our class extends the built-in ``DatabaseSession`` so we don't have to duplicate all of its logic and behavior. We wrap each operation with a :php:class:`Cake\\Cache\\Cache` operation. This lets us fetch sessions from the fast cache, and not have to worry about what happens when we fill the cache. -Using this session handler is also easy. In your **app.php** make the session -block look like the following:: +Using this session handler is also easy. In **config/app.php** make the session +block look like:: 'Session' => [ 'defaults' => 'database', @@ -405,8 +405,8 @@ Flash messages are small messages displayed to end users once. They are often used to present error messages, or confirm that actions took place successfully. To set and display flash messages you should use -:doc:`/controllers/components/flash` and -:doc:`/views/helpers/flash` +:doc:`FlashComponent ` and +:doc:`FlashHelper ` .. meta:: :title lang=en: Sessions diff --git a/en/views.rst b/en/views.rst index 0c1174018b..ff25e42584 100644 --- a/en/views.rst +++ b/en/views.rst @@ -152,7 +152,7 @@ Any variables you set in your controller with ``set()`` will be available in both the view and the layout your action renders. In addition, any set variables will also be available in any element. If you need to pass additional variables from the view to the layout you can either call ``set()`` in the view template, -or use a :ref:`view-blocks`. +or use :ref:`View Blocks `. You should remember to **always** escape any user data before outputting it as CakePHP does not automatically escape output. You can escape user content with @@ -653,7 +653,7 @@ if you are in the ``ContactsController`` of the Contacts plugin, the following:: are equivalent and will result in the same element being rendered. For elements inside subfolder of a plugin -(e.g., **plugins/Contacts/Template/Element/sidebar/helpbox.php**), use the +(e.g., **plugins/Contacts/Template/element/sidebar/helpbox.php**), use the following:: echo $this->element('Contacts.sidebar/helpbox'); diff --git a/en/views/helpers/flash.rst b/en/views/helpers/flash.rst index 8cb06c6aa8..bde16c66a1 100644 --- a/en/views/helpers/flash.rst +++ b/en/views/helpers/flash.rst @@ -9,7 +9,7 @@ FlashHelper provides a way to render flash messages that were set in ``$_SESSION`` by :doc:`FlashComponent `. :doc:`FlashComponent ` and FlashHelper primarily use elements to render flash messages. Flash elements are found under -the **templates/Element/Flash** directory. You'll notice that CakePHP's App +the **templates/element/Flash** directory. You'll notice that CakePHP's App template comes with three flash elements: **success.php**, **default.php**, and **error.php**. @@ -53,7 +53,7 @@ Routing Prefix and Flash Messages ================================= If you have a Routing prefix configured, you can now have your Flash elements -stored in **templates/{Prefix}/Element/Flash**. This way, you can have +stored in **templates/{Prefix}/element/Flash**. This way, you can have specific messages layouts for each part of your application. For instance, using different layouts for your front-end and admin section. @@ -62,5 +62,5 @@ Flash Messages and Themes The FlashHelper uses normal elements to render the messages and will therefore obey any theme you might have specified. So when your theme has a -**templates/Element/Flash/error.php** file it will be used, just as with any +**templates/element/Flash/error.php** file it will be used, just as with any Elements and Views. diff --git a/en/views/helpers/form.rst b/en/views/helpers/form.rst index b166b83580..c5efe339bb 100644 --- a/en/views/helpers/form.rst +++ b/en/views/helpers/form.rst @@ -1651,9 +1651,10 @@ Creating Year Controls * ``$options`` - An optional array including any of the :ref:`general-control-options` as well as any valid HTML attributes. Other valid options are: - - ``min`: The lowest value to use in the year select picker. - - ``max``: The maximum value to use in the year select picker. - - ``order``: The order of year values in the year select picker. + + * ``min``: The lowest value to use in the year select picker. + * ``max``: The maximum value to use in the year select picker. + * ``order``: The order of year values in the year select picker. Possible values are ``'asc'`` and ``'desc'``. Defaults to ``'desc'``. Creates a ``select`` element populated with the years from ``min`` to ``max`` diff --git a/en/views/helpers/html.rst b/en/views/helpers/html.rst index b8103e3aad..d614c892c7 100644 --- a/en/views/helpers/html.rst +++ b/en/views/helpers/html.rst @@ -792,67 +792,6 @@ When loading files of templates, your file should look like:: ``%%``. The reason is that internally templates are compiled to be used with ``sprintf()``. Example: ``
{{content}}
`` -Creating Breadcrumb Trails with HtmlHelper -========================================== - -.. php:method:: addCrumb(string $name, string $link = null, mixed $options = null) -.. php:method:: getCrumbs(string $separator = '»', string $startText = false) -.. php:method:: getCrumbList(array $options = [], $startText = false) - -Many applications have breadcrumb trails to ease end user navigations. You can -create a breadcrumb trail in your app with some help from HtmlHelper. To make -bread crumbs, first the following in your layout -template:: - - echo $this->Html->getCrumbs(' > ', 'Home'); - -The ``$startText`` option can also accept an array. This gives more control -over the generated first link:: - - echo $this->Html->getCrumbs(' > ', [ - 'text' => $this->Html->image('home.png'), - 'url' => ['controller' => 'Pages', 'action' => 'display', 'home'], - 'escape' => false - ]); - -Any keys that are not ``text`` or ``url`` will be passed to -:php:meth:`~HtmlHelper::link()` as the ``$options`` parameter. - -Now, in your view you'll want to add the following to start the -breadcrumb trails on each of the pages:: - - $this->Html->addCrumb('Users', '/users'); - $this->Html->addCrumb('Add User', ['controller' => 'Users', 'action' => 'add']); - -This will add the output of "**Home > Users > Add User**" in your layout where -``getCrumbs`` was added. - -You can also fetch the crumbs formatted inside an HTML list:: - - echo $this->Html->getCrumbList(); - -As options you can use regular HTML parameter that fits in the ``
    `` -(Unordered List) such as ``class`` and for the specific options, you have: -``separator`` (will be between the ``
  • `` elements), ``firstClass`` and -``lastClass`` like:: - - echo $this->Html->getCrumbList( - [ - 'firstClass' => false, - 'lastClass' => 'active', - 'class' => 'breadcrumb' - ], - 'Home' - ); - -This method uses :php:meth:`Cake\\View\\Helper\\HtmlHelper::tag()` to generate -list and its elements. Works similar to -:php:meth:`~Cake\\View\\Helper\\HtmlHelper::getCrumbs()`, so it uses options -which every crumb was added with. You can use the ``$startText`` parameter to -provide the first breadcrumb link/text. This is useful when you always want to -include a root link. This option works the same as the ``$startText`` option for -:php:meth:`~Cake\\View\\Helper\\HtmlHelper::getCrumbs()`. - .. meta:: :title lang=en: HtmlHelper :description lang=en: The role of the HtmlHelper in CakePHP is to make HTML-related options easier, faster, and more resilient to change. diff --git a/en/views/json-and-xml-views.rst b/en/views/json-and-xml-views.rst index 34694e90bd..52fbda5507 100644 --- a/en/views/json-and-xml-views.rst +++ b/en/views/json-and-xml-views.rst @@ -131,12 +131,6 @@ You can do more complex manipulations, or use helpers to do formatting as well. The data view classes don't support layouts. They assume that the view file will output the serialized content. -.. note:: - As of 3.1.0 AppController, in the application skeleton automatically adds - ``'_serialize' => true`` to all XML/JSON requests. You will need to remove - this code from the beforeRender callback or set ``'_serialize' => false`` in - your controller's action if you want to use view files. - Creating XML Views ================== From 382238ad43931d745b09b1919c0e81f3e6c19bbd Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 5 Apr 2019 13:24:45 -0400 Subject: [PATCH 2/2] Fix config method usage. --- en/controllers/components.rst | 12 +++---- en/controllers/components/authentication.rst | 32 +++++++++---------- en/controllers/components/pagination.rst | 2 +- .../components/request-handling.rst | 2 +- en/controllers/components/security.rst | 9 +----- en/core-libraries/caching.rst | 28 ++++++++-------- en/core-libraries/email.rst | 8 ++--- en/core-libraries/logging.rst | 32 +++++++++---------- en/core-libraries/number.rst | 2 +- en/development/configuration.rst | 6 ++-- en/orm/behaviors.rst | 4 +-- en/orm/behaviors/tree.rst | 4 +-- en/orm/database-basics.rst | 16 +++++----- en/orm/table-objects.rst | 4 +-- en/views/helpers.rst | 4 +-- 15 files changed, 79 insertions(+), 86 deletions(-) diff --git a/en/controllers/components.rst b/en/controllers/components.rst index 883db005ed..067bad7bde 100644 --- a/en/controllers/components.rst +++ b/en/controllers/components.rst @@ -45,27 +45,27 @@ Controller's ``initialize()`` method or via the ``$components`` array:: } -You can configure components at runtime using the ``config()`` method. Often, +You can configure components at runtime using the ``setConfig()`` method. Often, this is done in your controller's ``beforeFilter()`` method. The above could also be expressed as:: public function beforeFilter(EventInterface $event) { - $this->RequestHandler->config('viewClassMap', ['rss' => 'MyRssView']); + $this->RequestHandler->setConfig('viewClassMap', ['rss' => 'MyRssView']); } -Like helpers, components implement a ``config()`` method that is used to get and +Like helpers, components implement a ``getConfig()`` method that is used to get and set any configuration data for a component:: // Read config data. - $this->RequestHandler->config('viewClassMap'); + $this->RequestHandler->getConfig('viewClassMap'); // Set config - $this->Csrf->config('cookieName', 'token'); + $this->Csrf->setConfig('cookieName', 'token'); As with helpers, components will automatically merge their ``$_defaultConfig`` property with constructor configuration to create the ``$_config`` property -which is accessible with ``config()``. +which is accessible with ``getConfig()`` and ``setConfig()``. Aliasing Components ------------------- diff --git a/en/controllers/components/authentication.rst b/en/controllers/components/authentication.rst index 4a6f0c5fef..2a97b93172 100644 --- a/en/controllers/components/authentication.rst +++ b/en/controllers/components/authentication.rst @@ -78,10 +78,10 @@ configuration information into each authentication object using an array:: // Simple setup - $this->Auth->config('authenticate', ['Form']); + $this->Auth->setConfig('authenticate', ['Form']); // Pass settings in - $this->Auth->config('authenticate', [ + $this->Auth->setConfig('authenticate', [ 'Basic' => ['userModel' => 'Members'], 'Form' => ['userModel' => 'Members'] ]); @@ -93,7 +93,7 @@ to every attached object. The ``all`` key is also exposed as ``AuthComponent::ALL``:: // Pass settings in using 'all' - $this->Auth->config('authenticate', [ + $this->Auth->setConfig('authenticate', [ AuthComponent::ALL => ['userModel' => 'Members'], 'Basic', 'Form' @@ -514,7 +514,7 @@ Using Custom Authentication Objects Once you've created your custom authentication objects, you can use them by including them in ``AuthComponent``'s authenticate array:: - $this->Auth->config('authenticate', [ + $this->Auth->setConfig('authenticate', [ 'Openid', // app authentication object. 'AuthBag.Openid', // plugin authentication object. ]); @@ -560,7 +560,7 @@ messages ``AuthComponent`` uses. In your controller's ``beforeFilter()``, or component settings you can use ``authError`` to customize the error used for when authorization fails:: - $this->Auth->config('authError', "Woopsie, you are not authorized to access this area."); + $this->Auth->setConfig('authError', "Woopsie, you are not authorized to access this area."); Sometimes, you want to display the authorization error only after the user has already logged-in. You can suppress this message by setting @@ -569,7 +569,7 @@ its value to boolean ``false``. In your controller's ``beforeFilter()`` or component settings:: if (!$this->Auth->user()) { - $this->Auth->config('authError', false); + $this->Auth->setConfig('authError', false); } .. _hashing-passwords: @@ -784,7 +784,7 @@ In some cases you may want to use ``$this->Auth->user()`` in the authentication checks should be done:: //Set up AuthComponent to authenticate in initialize() - $this->Auth->config('checkAuthIn', 'Controller.initialize'); + $this->Auth->setConfig('checkAuthIn', 'Controller.initialize'); Default value for ``checkAuthIn`` is ``'Controller.startup'`` - but by using ``'Controller.initialize'`` initial authentication is done before ``beforeFilter()`` @@ -833,10 +833,10 @@ configuration information into each authorization object, using an array:: // Basic setup - $this->Auth->config('authorize', ['Controller']); + $this->Auth->setConfig('authorize', ['Controller']); // Pass settings in - $this->Auth->config('authorize', [ + $this->Auth->setConfig('authorize', [ 'Actions' => ['actionPath' => 'controllers/'], 'Controller' ]); @@ -847,7 +847,7 @@ to set settings that are passed to every attached object. The ``all`` key is also exposed as ``AuthComponent::ALL``:: // Pass settings in using 'all' - $this->Auth->config('authorize', [ + $this->Auth->setConfig('authorize', [ AuthComponent::ALL => ['actionPath' => 'controllers/'], 'Actions', 'Controller' @@ -898,7 +898,7 @@ Using Custom Authorize Objects Once you've created your custom authorize object, you can use them by including them in your ``AuthComponent``'s authorize array:: - $this->Auth->config('authorize', [ + $this->Auth->setConfig('authorize', [ 'Ldap', // app authorize object. 'AuthBag.Combo', // plugin authorize object. ]); @@ -908,7 +908,7 @@ Using No Authorization If you'd like to not use any of the built-in authorization objects and want to handle things entirely outside of ``AuthComponent``, you can set -``$this->Auth->config('authorize', false);``. By default ``AuthComponent`` +``$this->Auth->setConfig('authorize', false);``. By default ``AuthComponent`` starts off with ``authorize`` set to ``false``. If you don't use an authorization scheme, make sure to check authorization yourself in your controller's ``beforeFilter()`` or with another component. @@ -1012,7 +1012,7 @@ Configuration options ===================== The following settings can all be defined either in your controller's -``initialize()`` method or using ``$this->Auth->config()`` in your ``beforeFilter()``: +``initialize()`` method or using ``$this->Auth->setConfig()`` in your ``beforeFilter()``: ajaxLogin The name of an optional view element to render when an AJAX request is made @@ -1070,12 +1070,12 @@ checkAuthIn if you want the check to be done before controller's ``beforeFilter()`` method is run. -You can get current configuration values by calling ``$this->Auth->config()``:: +You can get current configuration values by calling ``$this->Auth->getConfig()``:: only the configuration option:: - $this->Auth->config('loginAction'); + $this->Auth->getConfig('loginAction'); - $this->redirect($this->Auth->config('loginAction')); + $this->redirect($this->Auth->getConfig('loginAction')); This is useful if you want to redirect a user to the ``login`` route for example. Without a parameter, the full configuration will be returned. diff --git a/en/controllers/components/pagination.rst b/en/controllers/components/pagination.rst index 913e5c066c..ef64ab8006 100644 --- a/en/controllers/components/pagination.rst +++ b/en/controllers/components/pagination.rst @@ -232,7 +232,7 @@ additional details on how to use the table registry:: ]; // Register an additional table object to allow differentiating in pagination component - TableRegistry::config('UnpublishedArticles', [ + TableRegistry::getTableLocator()->setConfig('UnpublishedArticles', [ 'className' => 'App\Model\Table\ArticlesTable', 'table' => 'articles', 'entityClass' => 'App\Model\Entity\Article', diff --git a/en/controllers/components/request-handling.rst b/en/controllers/components/request-handling.rst index b27fbfa4da..b2dc483b51 100644 --- a/en/controllers/components/request-handling.rst +++ b/en/controllers/components/request-handling.rst @@ -167,7 +167,7 @@ callbacks like ``json_decode``:: $this->RequestHandler->addInputType('json', ['json_decode', true]); // After 3.1.0 you should use - $this->RequestHandler->config('inputTypeMap.json', ['json_decode', true]); + $this->RequestHandler->setConfig('inputTypeMap.json', ['json_decode', true]); The above will make ``$this->request->getData()`` an array of the JSON input data, without the additional ``true`` you'd get a set of ``stdClass`` objects. diff --git a/en/controllers/components/security.rst b/en/controllers/components/security.rst index fd226dae9c..df8a929dec 100644 --- a/en/controllers/components/security.rst +++ b/en/controllers/components/security.rst @@ -76,10 +76,6 @@ works:: // redirect to HTTPS version of the requested page. } -.. note:: - - use ``$this->Security->config()`` for CakePHP versions prior to 3.4 - The ``$type`` parameter can have the following values: * 'auth' Indicates a form validation error, or a controller/action mismatch @@ -114,8 +110,7 @@ allowedActions This can be used to control cross controller requests. These configuration options allow you to restrict cross controller -communication. Set them with the ``setConfig()`` method, or -``config()`` if you are using a CakePHP version below 3.4. +communication. Form Tampering Prevention ========================= @@ -149,8 +144,6 @@ validatePost Set to ``false`` to completely skip the validation of POST requests, essentially turning off form validation. -The above configuration options can be set with ``setConfig()`` or -``config()`` for CakePHP versions below 3.4. Usage ===== diff --git a/en/core-libraries/caching.rst b/en/core-libraries/caching.rst index 1bec153457..b74a753cdc 100644 --- a/en/core-libraries/caching.rst +++ b/en/core-libraries/caching.rst @@ -44,7 +44,7 @@ Regardless of the CacheEngine you choose to use, your application interacts with Configuring Cache Engines ========================= -.. php:staticmethod:: config($key, $config = null) +.. php:staticmethod:: setConfig($key, $config = null) Your application can configure any number of 'engines' during its bootstrap process. Cache engine configurations are defined in **config/app.php**. @@ -81,7 +81,7 @@ following:: Configuration options can also be provided as a :term:`DSN` string. This is useful when working with environment variables or :term:`PaaS` providers:: - Cache::config('short', [ + Cache::setConfig('short', [ 'url' => 'memcached://user:password@cache-host/?timeout=3600&prefix=myapp_', ]); @@ -91,7 +91,7 @@ query string arguments. You can also configure Cache engines at runtime:: // Using a short name - Cache::config('short', [ + Cache::setConfig('short', [ 'className' => 'File', 'duration' => '+1 hours', 'path' => CACHE, @@ -99,7 +99,7 @@ You can also configure Cache engines at runtime:: ]); // Using a fully namespaced name. - Cache::config('long', [ + Cache::setConfig('long', [ 'className' => 'Cake\Cache\Engine\FileEngine', 'duration' => '+1 week', 'probability' => 100, @@ -108,7 +108,7 @@ You can also configure Cache engines at runtime:: // Using a constructed object. $object = new FileEngine($config); - Cache::config('other', $object); + Cache::setConfig('other', $object); The name of these engine configurations ('short' and 'long') are used as the ``$config`` parameter for :php:meth:`Cake\\Cache\\Cache::write()` and @@ -116,16 +116,16 @@ parameter for :php:meth:`Cake\\Cache\\Cache::write()` and refer to the class name using the following syntaxes:: // Short name (in App\ or Cake namespaces) - Cache::config('long', ['className' => 'File']); + Cache::setConfig('long', ['className' => 'File']); // Plugin short name - Cache::config('long', ['className' => 'MyPlugin.SuperCache']); + Cache::setConfig('long', ['className' => 'MyPlugin.SuperCache']); // Full namespace - Cache::config('long', ['className' => 'Cake\Cache\Engine\FileEngine']); + Cache::setConfig('long', ['className' => 'Cake\Cache\Engine\FileEngine']); // An object implementing CacheEngineInterface - Cache::config('long', ['className' => $myCache]); + Cache::setConfig('long', ['className' => $myCache]); .. note:: @@ -199,7 +199,7 @@ cache failure. You can configure Cache configurations to fall back to a specified config using the ``fallback`` configuration key:: - Cache::config('redis', [ + Cache::setConfig('redis', [ 'className' => 'Redis', 'duration' => '+1 hours', 'prefix' => 'cake_redis_', @@ -216,7 +216,7 @@ from throwing an uncaught exception. You can turn off cache fallbacks with ``false``:: - Cache::config('redis', [ + Cache::setConfig('redis', [ 'className' => 'Redis', 'duration' => '+1 hours', 'prefix' => 'cake_redis_', @@ -234,7 +234,7 @@ Removing Configured Cache Engines Once a configuration is created you cannot change it. Instead you should drop the configuration and re-create it using :php:meth:`Cake\\Cache\\Cache::drop()` and -:php:meth:`Cake\\Cache\\Cache::config()`. Dropping a cache engine will remove +:php:meth:`Cake\\Cache\\Cache::setConfig()`. Dropping a cache engine will remove the config and destroy the adapter if it was constructed. Writing to a Cache @@ -462,7 +462,7 @@ group or namespace. This is a common requirement for mass-invalidating keys whenever some information changes that is shared among all entries in the same group. This is possible by declaring the groups in cache configuration:: - Cache::config('site_home', [ + Cache::setConfig('site_home', [ 'className' => 'Redis', 'duration' => '+999 days', 'groups' => ['comment', 'article'] @@ -548,7 +548,7 @@ Or in **plugins/MyPlugin/src/Cache/Engine/MyCustomCacheEngine.php** as part of a plugin. Cache configs from plugins need to use the plugin dot syntax:: - Cache::config('custom', [ + Cache::setConfig('custom', [ 'className' => 'MyPlugin.MyCustomCache', // ... ]); diff --git a/en/core-libraries/email.rst b/en/core-libraries/email.rst index 9aada4b43a..8f10c5c948 100644 --- a/en/core-libraries/email.rst +++ b/en/core-libraries/email.rst @@ -57,8 +57,8 @@ original sender using the Sender header. You can do so using ``setSender()``:: Configuration ============= -Configuration for ``Email`` defaults is created using ``config()`` and -``configTransport()``. You should put your email presets in the +Configuration for ``Email`` defaults is created using ``setConfig()`` and +``TransportFactory::setConfig()``. You should put your email presets in the **config/app.php** file. The **config/app.default.php** file is an example of this file. It is not required to define email configuration in **config/app.php**. ``Email`` can be used without it and use the respective @@ -381,7 +381,7 @@ transport). To start off your file should look like:: } You must implement the method ``send(Email $email)`` with your custom logic. -Optionally, you can implement the ``config($config)`` method. ``config()`` is +Optionally, you can implement the ``setConfig($config)`` method. ``setConfig()`` is called before send() and allows you to accept user configurations. By default, this method puts the configuration in protected attribute ``$_config``. @@ -416,7 +416,7 @@ want do setup a bunch of configuration ahead of time. :php:meth:`Cake\\Mailer\\Email::deliver()` is intended for that purpose. You can create your configuration using -:php:meth:`Cake\\Mailer\\Email::config()`, or use an array with all +:php:meth:`Cake\\Mailer\\Email::setConfig()`, or use an array with all options that you need and use the static method ``Email::deliver()``. Example:: diff --git a/en/core-libraries/logging.rst b/en/core-libraries/logging.rst index c689ff3851..b23e5c7dca 100644 --- a/en/core-libraries/logging.rst +++ b/en/core-libraries/logging.rst @@ -31,7 +31,7 @@ configured using :php:class:`Cake\\Log\\Log`. An example would be:: use Cake\Log\Log; // Short classname - Log::config('debug', [ + Log::setConfig('debug', [ 'className' => 'File', 'path' => LOGS, 'levels' => ['notice', 'info', 'debug'], @@ -39,7 +39,7 @@ configured using :php:class:`Cake\\Log\\Log`. An example would be:: ]); // Fully namespaced name. - Log::config('error', [ + Log::setConfig('error', [ 'className' => 'Cake\Log\Engine\FileLog', 'path' => LOGS, 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], @@ -54,20 +54,20 @@ information on the different levels and what they mean. Once a configuration is created you cannot change it. Instead you should drop the configuration and re-create it using :php:meth:`Cake\\Log\\Log::drop()` and -:php:meth:`Cake\\Log\\Log::config()`. +:php:meth:`Cake\\Log\\Log::setConfig()`. It is also possible to create loggers by providing a closure. This is useful when you need full control over how the logger object is built. The closure has to return the constructed logger instance. For example:: - Log::config('special', function () { + Log::setConfig('special', function () { return new \Cake\Log\Engine\FileLog(['path' => LOGS, 'file' => 'log']); }); Configuration options can also be provided as a :term:`DSN` string. This is useful when working with environment variables or :term:`PaaS` providers:: - Log::config('error', [ + Log::setConfig('error', [ 'url' => 'file:///?levels[]=warning&levels[]=error&file=error', ]); @@ -83,18 +83,18 @@ plugins. If for example you had a database logger called ``DatabaseLog``. As part of your application it would be placed in **src/Log/Engine/DatabaseLog.php**. As part of a plugin it would be placed in **plugins/LoggingPack/src/Log/Engine/DatabaseLog.php**. To configure log -adapters you should use :php:meth:`Cake\\Log\\Log::config()`. For example +adapters you should use :php:meth:`Cake\\Log\\Log::setConfig()`. For example configuring our DatabaseLog would look like:: // For src/Log - Log::config('otherFile', [ + Log::setConfig('otherFile', [ 'className' => 'Database', 'model' => 'LogEntry', // ... ]); // For plugin called LoggingPack - Log::config('otherFile', [ + Log::setConfig('otherFile', [ 'className' => 'LoggingPack.Database', 'model' => 'LogEntry', // ... @@ -189,7 +189,7 @@ You can configure additional/alternate FileLog locations when configuring a logger. FileLog accepts a ``path`` which allows for custom paths to be used:: - Log::config('custom_path', [ + Log::setConfig('custom_path', [ 'className' => 'File', 'path' => '/path/to/custom/place/' ]); @@ -213,7 +213,7 @@ to specify ``Syslog`` as the engine to be used for logging. The following configuration snippet will replace the default logger with syslog, this should be done in the **bootstrap.php** file:: - Log::config('default', [ + Log::setConfig('default', [ 'engine' => 'Syslog' ]); @@ -298,7 +298,7 @@ the log messages will be directed to those loggers. For example:: // Configure logs/shops.log to receive all levels, but only // those with `orders` and `payments` scope. - Log::config('shops', [ + Log::setConfig('shops', [ 'className' => 'File', 'path' => LOGS, 'levels' => [], @@ -308,7 +308,7 @@ the log messages will be directed to those loggers. For example:: // Configure logs/payments.log to receive all levels, but only // those with `payments` scope. - Log::config('payments', [ + Log::setConfig('payments', [ 'className' => 'File', 'path' => LOGS, 'levels' => [], @@ -339,7 +339,7 @@ Log API A simple class for writing to logs. -.. php:staticmethod:: config($key, $config) +.. php:staticmethod:: setConfig($key, $config) :param string $name: Name for the logger being connected, used to drop a logger later on. @@ -408,14 +408,14 @@ the CakePHP loggers, it is easy to use in your application as the default logger. After installing Monolog using composer, configure the logger using the -``Log::config()`` method:: +``Log::setConfig()`` method:: // config/bootstrap.php use Monolog\Logger; use Monolog\Handler\StreamHandler; - Log::config('default', function () { + Log::setConfig('default', function () { $log = new Logger('app'); $log->pushHandler(new StreamHandler('path/to/your/combined.log')); return $log; @@ -432,7 +432,7 @@ Use similar methods if you want to configure a different logger for your console use Monolog\Logger; use Monolog\Handler\StreamHandler; - Log::config('default', function () { + Log::setConfig('default', function () { $log = new Logger('cli'); $log->pushHandler(new StreamHandler('path/to/your/combined-cli.log')); return $log; diff --git a/en/core-libraries/number.rst b/en/core-libraries/number.rst index 3163acd5ff..446b7f4432 100644 --- a/en/core-libraries/number.rst +++ b/en/core-libraries/number.rst @@ -338,7 +338,7 @@ to various methods. Example:: - Number::config('en_IN', \NumberFormatter::CURRENCY, [ + Number::setConfig('en_IN', \NumberFormatter::CURRENCY, [ 'pattern' => '#,##,##0' ]); diff --git a/en/development/configuration.rst b/en/development/configuration.rst index 7e65b8757d..19cdd0afd3 100644 --- a/en/development/configuration.rst +++ b/en/development/configuration.rst @@ -18,7 +18,7 @@ Configuration is generally stored in either PHP or INI files, and loaded during the application bootstrap. CakePHP comes with one configuration file by default, but if required you can add additional configuration files and load them in your application's bootstrap code. :php:class:`Cake\\Core\\Configure` is used -for global configuration, and classes like ``Cache`` provide ``config()`` +for global configuration, and classes like ``Cache`` provide ``setConfig()`` methods to make configuration simple and transparent. Loading Additional Configuration Files @@ -31,7 +31,7 @@ configuration into multiple files. After creating each of the files in your use Cake\Core\Configure; use Cake\Core\Configure\Engine\PhpConfig; - Configure::config('default', new PhpConfig()); + Configure::setConfig('default', new PhpConfig()); Configure::load('app', 'default', false); Configure::load('other_config', 'default'); @@ -398,7 +398,7 @@ exist, a :php:class:`RuntimeException` will be thrown:: Reading and writing configuration files ======================================= -.. php:staticmethod:: config($name, $engine) +.. php:staticmethod:: setConfig($name, $engine) CakePHP comes with two built-in configuration file engines. :php:class:`Cake\\Core\\Configure\\Engine\\PhpConfig` is able to read PHP config diff --git a/en/orm/behaviors.rst b/en/orm/behaviors.rst index 545c418fd6..9f49f09dad 100644 --- a/en/orm/behaviors.rst +++ b/en/orm/behaviors.rst @@ -164,7 +164,7 @@ behavior should now look like:: public function slug(Entity $entity) { - $config = $this->config(); + $config = $this->getConfig(); $value = $entity->get($config['field']); $entity->set($config['slug'], Text::slug($value, $config['replacement'])); } @@ -311,7 +311,7 @@ respond to:: // e.g. if our parent calls $this->addBehavior('Timestamp'); // and we want to add an additional event if ($this->behaviors()->has('Timestamp')) { - $this->behaviors()->get('Timestamp')->config([ + $this->behaviors()->get('Timestamp')->setConfig([ 'events' => [ 'Users.login' => [ 'last_login' => 'always' diff --git a/en/orm/behaviors/tree.rst b/en/orm/behaviors/tree.rst index eb6ac880c1..464f3fe03a 100644 --- a/en/orm/behaviors/tree.rst +++ b/en/orm/behaviors/tree.rst @@ -214,12 +214,12 @@ In the previous example, all tree operations will be scoped to only the rows having the column ``country_name`` set to 'Brazil'. You can change the scoping on the fly by using the 'config' function:: - $this->behaviors()->Tree->config('scope', ['country_name' => 'France']); + $this->behaviors()->Tree->setConfig('scope', ['country_name' => 'France']); Optionally, you can have a finer grain control of the scope by passing a closure as the scope:: - $this->behaviors()->Tree->config('scope', function ($query) { + $this->behaviors()->Tree->setConfig('scope', function ($query) { $country = $this->getConfigureContry(); // A made-up function return $query->where(['country_name' => $country]); }); diff --git a/en/orm/database-basics.rst b/en/orm/database-basics.rst index e43a4772e4..626118aeac 100644 --- a/en/orm/database-basics.rst +++ b/en/orm/database-basics.rst @@ -19,7 +19,7 @@ The easiest way to create a database connection is using a ``DSN`` string:: use Cake\Datasource\ConnectionManager; $dsn = 'mysql://root:password@localhost/my_database'; - ConnectionManager::config('default', ['url' => $dsn]); + ConnectionManager::setConfig('default', ['url' => $dsn]); Once created, you can access the connection object to start using it:: @@ -150,12 +150,12 @@ like:: The above will create a 'default' connection, with the provided parameters. You can define as many connections as you want in your configuration file. You can also define additional connections at runtime using -:php:meth:`Cake\\Datasource\\ConnectionManager::config()`. An example of that +:php:meth:`Cake\\Datasource\\ConnectionManager::setConfig()`. An example of that would be:: use Cake\Datasource\ConnectionManager; - ConnectionManager::config('default', [ + ConnectionManager::setConfig('default', [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, @@ -171,7 +171,7 @@ would be:: Configuration options can also be provided as a :term:`DSN` string. This is useful when working with environment variables or :term:`PaaS` providers:: - ConnectionManager::config('default', [ + ConnectionManager::setConfig('default', [ 'url' => 'mysql://my_app:sekret@localhost/my_app?encoding=utf8&timezone=UTC&cacheMetadata=true', ]); @@ -291,10 +291,10 @@ Attempting to load connections that do not exist will throw an exception. Creating Connections at Runtime ------------------------------- -Using ``config()`` and ``get()`` you can create new connections that are not +Using ``setConfig()`` and ``get()`` you can create new connections that are not defined in your configuration files at runtime:: - ConnectionManager::config('my_connection', $config); + ConnectionManager::setConfig('my_connection', $config); $conn = ConnectionManager::get('my_connection'); See the :ref:`database-configuration` for more information on the configuration @@ -855,14 +855,14 @@ files/syslog can be useful when working with web requests:: use Cake\Log\Log; // Console logging - Log::config('queries', [ + Log::setConfig('queries', [ 'className' => 'Console', 'stream' => 'php://stderr', 'scopes' => ['queriesLog'] ]); // File logging - Log::config('queries', [ + Log::setConfig('queries', [ 'className' => 'File', 'path' => LOGS, 'file' => 'queries.log', diff --git a/en/orm/table-objects.rst b/en/orm/table-objects.rst index 0632816787..fd10ad63dd 100644 --- a/en/orm/table-objects.rst +++ b/en/orm/table-objects.rst @@ -466,11 +466,11 @@ string values but objects. The connection will take an object of If your table also does additional configuration in its ``initialize()`` method, those values will overwrite the ones provided to the registry. -You can also pre-configure the registry using the ``config()`` method. +You can also pre-configure the registry using the ``setConfig()`` method. Configuration data is stored *per alias*, and can be overridden by an object's ``initialize()`` method:: - TableRegistry::config('Users', ['table' => 'my_users']); + TableRegistry::getTableLocator()->setConfig('Users', ['table' => 'my_users']); .. note:: diff --git a/en/views/helpers.rst b/en/views/helpers.rst index 8832701ec5..d6d8c4c235 100644 --- a/en/views/helpers.rst +++ b/en/views/helpers.rst @@ -141,10 +141,10 @@ your helper requires. For example:: Any configuration provided to your helper's constructor will be merged with the default values during construction and the merged data will be set to -``_config``. You can use the ``config()`` method to read runtime configuration:: +``_config``. You can use the ``getConfig()`` method to read runtime configuration:: // Read the errorClass config option. - $class = $this->Awesome->config('errorClass'); + $class = $this->Awesome->getConfig('errorClass'); Using helper configuration allows you to declaratively configure your helpers and keep configuration logic out of your controller actions. If you have