El 30/11/2009, a las 9:35, Ernesto escribió:
> too many ifs in my controllers.
It think this is unavoidable.
Setting the argument with a default value of null avoid the PHP error
of "missing argument",
function edit($id = null) {...}
but you need to give some response to the situation.
Only the proper action "knows" how many arguments are mandatory, so
you need to check if they are set and valid. The default value
approach "normalizes" the arguments for the validation check. (Your
approach takes two steps: check argument's existence and validation).
You could ignore the argument fault and delegate to the view to deal
with the absence of data to edit/show:
In the controller simply let the action try to find the item with the
id of null. The result will be false, no ifs needed. Then, in the view:
if (!$item) {
echo 'No valid data to edit/show':
} else {...}
If this logic must go in the controller or in the view depends on
several factors.
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
No comments:
Post a Comment