Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci skip] Update RESTful User Guide #2321

Merged
merged 3 commits into from
Oct 11, 2019
Merged
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
59 changes: 43 additions & 16 deletions user_guide_src/source/incoming/restful.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ name::
$routes->resource('photos');

// Equivalent to the following:
$routes->get('photos', 'Photos::index');
$routes->get('photos/new', 'Photos::new');
$routes->get('photos/(:segment)/edit', 'Photos::edit/$1');
$routes->get('photos/(:segment)', 'Photos::show/$1');
$routes->post('photos', 'Photos::create');
$routes->delete('photos/(:segment)', 'Photos::delete/$1');
$routes->patch('photos/(:segment)', 'Photos::update/$1');
$routes->get('photos', 'Photos::index');
$routes->get('photos/(:segment)', 'Photos::show/$1');
$routes->get('photos/(:segment)/edit', 'Photos::edit/$1');
$routes->put('photos/(:segment)', 'Photos::update/$1');
$routes->patch('photos/(:segment)', 'Photos::update/$1');
$routes->delete('photos/(:segment)', 'Photos::delete/$1');

.. note:: The ordering above is for clarity, whereas the actual order the routes are created in, in RouteCollection, ensures proper route resolution

.. important:: The routes are matched in the order they are specified, so if you have a resource photos above a get 'photos/poll' the show action's route for the resource line will be matched before the get line. To fix this, move the get line above the resource line so that it is matched first.

Expand Down Expand Up @@ -138,17 +140,19 @@ Its usage is similar to the resosurce routing::
$routes->presenter('photos');

// Equivalent to the following:
$routes->get('photos', 'Photos::index');
$routes->post('photos', 'Photos::create'); // alias
$routes->get('photos/show/(:segment)', 'Photos::show/$1');
$routes->get('photos/new', 'Photos::new');
$routes->post('photos/create', 'Photos::create');
$routes->get('photos/edit/(:segment)', 'Photos::edit/$1');
$routes->post('photos/update/(:segment)', 'Photos::update/$1');
$routes->get('photos/remove/(:segment)', 'Photos::remove/$1');
$routes->post('photos/delete/(:segment)', 'Photos::update/$1');
$routes->get('photos/(:segment)', 'Photos::show/$1'); // alias

$routes->get('photos/new', 'Photos::new');
$routes->post('photos/create', 'Photos::create');
$routes->post('photos', 'Photos::create'); // alias
$routes->get('photos', 'Photos::index');
$routes->get('photos/show/(:segment)', 'Photos::show/$1');
$routes->get('photos/(:segment)', 'Photos::show/$1'); // alias
$routes->get('photos/edit/(:segment)', 'Photos::edit/$1');
$routes->post('photos/update/(:segment)', 'Photos::update/$1');
$routes->get('photos/remove/(:segment)', 'Photos::remove/$1');
$routes->post('photos/delete/(:segment)', 'Photos::update/$1');

.. note:: The ordering above is for clarity, whereas the actual order the routes are created in, in RouteCollection, ensures proper route resolution

You would not have routes for `photos` for both a resource and a presenter
controller. You need to distinguish them, for instance::

Expand Down Expand Up @@ -227,3 +231,26 @@ implement those methods that you want handled.::
The routing for this would be::

$routes->presenter('photos');

Presenter/Controller Comparison
=============================================================

This table presents a comparison of the default routes created by `resource()`
and `presenter()` with their corresponding Controller functions.

=========== ========= ====================== ======================== ==================== ====================
Operation Method Controller Route Presenter Route Controller Function Presenter Function
=========== ========= ====================== ======================== ==================== ====================
**New** GET photos/new photos/new `new()` `new()`
**Create** POST photos photos `create()` `create()`
(alias) POST photos/create `create()`
**List** GET photos photos `index()` `index()`
**Show** GET photos/(:segment) photos/(:segment) `show($id = null)` `show($id = null)`
(alias) GET photos/show/(:segment) `show($id = null)`
**Edit** GET photos/(:segment)/edit photos/edit/(:segment) `edit($id = null)` `edit($id = null)`
**Update** PUT/PATCH photos/(:segment) `update($id = null)`
(websafe) POST photos/(:segment) photos/update/(:segment) `update($id = null)` `update($id = null)`
**Remove** GET photos/remove/(:segment) `remove($id = null)`
**Delete** DELETE photos/(:segment) `delete($id = null)`
(websafe) POST photos/delete/(:segment) `delete($id = null)` `delete($id = null)`
=========== ========= ====================== ======================== ==================== ====================