Skip to content

Commit

Permalink
Merge pull request cakephp#3837 from cakephp/3.3-nested-resources
Browse files Browse the repository at this point in the history
Add docs for nested resource routing.
  • Loading branch information
lorenzo committed Mar 20, 2016
2 parents e4c4a92 + 2930bcd commit 12df9f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion en/appendices/3-3-migration-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Routing
- ``Router::parse()``, ``RouteCollection::parse()`` and ``Route::parse()`` had
a ``$method`` argument added. It defaults to 'GET'. This new parameter reduces
reliance on global state, and necessary for the PSR7 work integration to be done.

- When building resource routes, you can now define a prefix. This is useful
when defining nested resources as you can create specialized controllers for
nested resources.

ORM
===
Expand Down
20 changes: 19 additions & 1 deletion en/development/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -749,13 +749,31 @@ comments routes will look like::

You can get the ``article_id`` in ``CommentsController`` by::

$this->request->params['article_id']
$this->request->param('article_id');

By default resource routes map to the same prefix as the containing scope. If
you have both nested and non-nested resource controllers you can use a different
controller in each context by using prefixes::

Router::scope('/api', function ($routes) {
$routes->resources('Articles', function ($routes) {
$routes->resources('Comments', ['prefix' => 'articles']);
});
});

The above would map the 'Comments' resource to the
``App\Controller\Articles\CommentsController``. Having separate controllers lets
you keep your controller logic simpler. The prefixes created this way are
compatible with :ref:`prefix-routing`.

.. note::

While you can nest resources as deeply as you require, it is not recommended
to nest more than 2 resources together.

.. versionadded:: 3.3
The ``prefix`` option was added to ``resources()`` in 3.3.

Limiting the Routes Created
---------------------------

Expand Down

0 comments on commit 12df9f8

Please sign in to comment.