Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions en/controllers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 8 additions & 12 deletions en/controllers/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,35 @@ 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']);
}

}

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->Auth->config('authorize', ['controller']);
$this->Auth->config('loginAction', ['controller' => 'Users', 'action' => 'login']);

$this->Cookie->config('name', 'CookieMonster');
$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
Comment thread
garas marked this conversation as resolved.
set any configuration data for a component::

// Read config data.
$this->Auth->config('loginAction');
$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
-------------------
Expand Down
32 changes: 16 additions & 16 deletions en/controllers/components/authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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']
]);
Expand All @@ -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'
Expand Down Expand Up @@ -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.
]);
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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()``
Expand Down Expand Up @@ -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'
]);
Expand All @@ -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'
Expand Down Expand Up @@ -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.
]);
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions en/controllers/components/flash.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,7 +64,7 @@ An example of using these options::
// In your View
<?= $this->Flash->render('positive') ?>

<!-- In templates/Element/Flash/success.php -->
<!-- In templates/element/Flash/success.php -->
<div id="flash-<?= h($key) ?>" class="message-info success">
<?= h($message) ?>: <?= h($params['name']) ?>, <?= h($params['email']) ?>.
</div>
Expand All @@ -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::
Expand Down
2 changes: 1 addition & 1 deletion en/controllers/components/pagination.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion en/controllers/components/request-handling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 1 addition & 8 deletions en/controllers/components/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
=========================
Expand Down Expand Up @@ -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
=====
Expand Down
28 changes: 14 additions & 14 deletions en/core-libraries/caching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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**.
Expand Down Expand Up @@ -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_',
]);

Expand All @@ -91,15 +91,15 @@ 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,
'prefix' => 'cake_short_'
]);

// Using a fully namespaced name.
Cache::config('long', [
Cache::setConfig('long', [
'className' => 'Cake\Cache\Engine\FileEngine',
'duration' => '+1 week',
'probability' => 100,
Expand All @@ -108,24 +108,24 @@ 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
:php:meth:`Cake\\Cache\\Cache::read()`. When configuring cache engines you can
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::

Expand Down Expand Up @@ -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_',
Expand All @@ -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_',
Expand All @@ -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
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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',
// ...
]);
Expand Down
Loading