-- ArticSun <[EMAIL PROTECTED]> wrote
(on Monday, 10 September 2007, 04:26 AM -0700):
> I got a controller with several methods like "option1Action",
> "option2Action" etc. These methods are very similar but they're called with
> different urls ("url/controller/option1", "url/controller/option2", etc.).
>
> My question is, if it is possible to have a default "method" which is called
> when a certain method is not found? Some kind of autoload, but then for
> methods instead of objects?
>
> How could I solve this?
Two ways:
* extend the __call() method. I sometimes do it this way:
public function __call($method, $args)
{
if ('Action' == substr($method, -6)) {
return $this->defaultAction();
}
throw new Exception('__call() is not overloaded for utility
methods');
}
* Add a route with a default action:
$route = new Zend_Controller_Router_Route(
'url/controller/:action/*',
array(
'module' => ...,
'controller' => ...,
'action' => 'default' // default action method to use
)
);
$router->addRoute('options', $route);
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/