forked from bastos/nicedog
Routing
jetviper21 edited this page Sep 13, 2010
·
6 revisions
Examples:
Routing::resources(“form”);
maps all default CRUD actions for the class FormController
- index – GET – /forms
- create – POST – /forms
- show – GET – /form/:id
- update – PUT – /form/:id
- note on PUT $POST[’method’] = ‘PUT’ must be set in order for it to route to the update function
- delete – DELETE – /form/:id
- note on DELETE $POST[’method’] = ‘DELETE’ must be set in order for it to route to the delete function
R('mypage/:id')->controller('MainController')->action('mypage')->on('GET');
maps the route mypage/1 etc to the mypage($id) method in the MainController
This can also be done with a shortcut
R(‘mypage/:id’, ‘MainController’, ‘mypage’, ‘GET’);
R('mypage/:id/:mydate/:update')->controller('MainController')->action('mypage')->on('POST');
R('mypage/(?P<id>[a-zA-Z0-9_-]+)/(?P<mydate>(19|20)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01]))/(?P<update>[a-zA-Z0-9_-]+)')->controller('MainController')->action('mypage')->on('POST');
See above i check to make sure the data is passed as 1999-01-01 see Regular Expression for more information
R('mypage/:id/(?P<mydate>(19|20)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01]))/:update')->controller('MainController')->action('mypage')->on('POST');