Thursday, June 28, 2012

Routes vs Type checking for Action Parameters, best practice?

Lets say I have a controller Books with an action view() defined as follows: 

class BooksController extends AppController {
public function view($id) {
// something
}
}

Let's assume that $id is supposed to be of a numeric type. 

I see two options; 

1) Setup the route so that it only connects for instance books/view/{integer} to  Books->view($id)
2) Have general routing like the defaults in CakePHP and include code in view() to make sure that $id is set and is numeric. 

Which is better practice? 

In my view I think the former is cleaner and less magicky. This is something I enjoyed working with the Play Framwork, that you explicitly had to connect a route to each action. 

What is your opinion?

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: