Skip to content

Instantly share code, notes, and snippets.

@agborkowski
Created October 16, 2014 09:59
Show Gist options
  • Save agborkowski/2d01f7e6e3d9393fd60a to your computer and use it in GitHub Desktop.
Save agborkowski/2d01f7e6e3d9393fd60a to your computer and use it in GitHub Desktop.
<?php
/**
* Lithium REST routes
* @author AgBorkowski <andrzejborkowski@gmail.com> http://blog.aeonmedia.eu
* @see http://book.cakephp.org/view/1239/The-Simple-Setup
* @see http://www.sencha.com/learn/Manual:RESTful_Web_Services#HTTP_Status_Codes
* Method-----URL------------------Controller action invoked
* GET......./recipes..............RecipesController::index()
* GET......./recipes/index........RecipesController::index()
*
* GET......./recipes/123..........RecipesController::view(123)
*
* POST....../recipes..............RecipesController::add()
* POST....../recipes/add..........RecipesController::add()
*
* PUT......./recipes..............RecipesController::edit()
* PUT......./recipes/123..........RecipesController::edit(123)
* POST....../recipes/123/edit.....RecipesController::edit()
*
* DELETE..../recipes..............RecipesController::delete()
* DELETE..../recipes/123..........RecipesController::delete(123)
* POST....../recipes/123..........RecipesController::edit(123)
*/
Router::connect('/{:controller}(.{:type:\w+})*', array('http:method' => 'GET', 'action' => 'index'));
Router::connect('/{:controller}/index(.{:type:\w+})*', array('http:method' => 'GET', 'action' => 'index'));
Router::connect(
'/{:controller}/{:id:[0-9a-f]{24}|[0-9]+}(.{:type:\w+})*',
array('http:method' => 'GET', 'action' => 'view')
);
Router::connect('/{:controller}(.{:type:\w+})*', array('http:method' => 'POST', 'action' => 'add'));
Router::connect('/{:controller}/add(.{:type:\w+})*', array('http:method' => 'POST', 'action' => 'add'));
Router::connect('/{:controller}(.{:type:\w+})*', array('http:method' => 'PUT', 'action' => 'edit'));
Router::connect(
'/{:controller}/{:id:[0-9a-f]{24}|[0-9]+}(.{:type:\w+})*',
array('http:method' => 'PUT', 'action' => 'edit')
);
Router::connect(
'/{:controller}/{:id:[0-9a-f]{24}|[0-9]+}(.{:type:\w+})*/edit',
array('http:method' => 'POST', 'action' => 'edit')
);
Router::connect(
'/{:controller}/{:id:[0-9a-f]{24}|[0-9]+}',
array('http:method' => 'POST', 'action' => 'edit')
);
Router::connect(
'/{:controller}',
array('http:method' => 'DELETE', 'action' => 'delete')
);
Router::connect(
'/{:controller}/{:id:[0-9a-f]{24}|[0-9]+}(.{:type:\w+})*',
array('http:method' => 'DELETE', 'action' => 'delete')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment