Request parameter mapping to action method parameters
albeva |
3 comments | October 3rd, 2009
I created a small extension to the Zend_Controller_Action that allows mapping request parameters to method parameters for clean and intuitive parameter passing from request to the action methods.
/** * @param int $page */public function indexAction($page = 1) { ... }
This not only makes parameter passing intuitive (rather than calling $this->_request->getParam() ) but also automatically uses the default value if provided and if typehinting is provided either via phpdoc comment or before the parameter (array or classname) it will do the required instantiation or type casting. For example above $page is safe to use as it is always cast to int.
More here: http://fbdevzone.com/2009/10/request-parameter-mapping/
Comments & suggestions are welcome


3 comments to “Request parameter mapping to action method parameters”
October 3rd, 2009 at 5:58 pm
I recall http://codeutopia.net/blog/2009/03/16/zend_controller-actions-that-accept-parameters/
October 3rd, 2009 at 7:02 pm
And how to configure Zend_Tool to extend from ZendX_Controller_Action by default?
October 3rd, 2009 at 8:53 pm
sudheerboss – didn’t know about this. Goes to prove that great minds think alike (or copy from others). Anyway his implementation differs from mine by being more strict and doesn’t seem to allow specifying classes.