views:

51

answers:

2

I haven't used the Zend Router much yet so not sure how difficult or easy this is, but I think Zend is flexible so it's got to have a way to do this easily.

So I create a controller Cont with 2 actions actone and acttwo. This naturally gives me

//the default index controller
site.com/                
site.com/index/index     

//and my controller
site.com/cont/index
site.com/cont/actone
site.com/cont/acttwo

Is there a way I can access the actone action which is in the cont controller using a route that looks like this

site.com/actone

I realize I could get this look by creating a separate controller called Actone and this would be its index action but this actone action logically belongs to the Cont controller, so I want to just give the appearance of that path.

+2  A: 

If you could make your Cont controller the default controller that would probably do the trick. IIRC this is in Zend_Controller_Dispatcher_Abstract, there's setDefaultControllerName() as well as setDefaultAction() and setDefaultModule().

Robin
+4  A: 

You can create a custom route...

Via application.ini's - Router Application Resource

resources.router.routes.route_title.route               = "/actone"
resources.router.routes.route_title.defaults.controller = "cont"
resources.router.routes.route_title.defaults.action     = "actone"
resources.router.routes.route_title.type                = "Zend_Controller_Router_Route_Static"

Or by adding one directly to the router.

$router = Zend_Controller_Front::getInstance()->getRouter();    
$router->addRoute('route_title', new Zend_Controller_Rotuer_Route_Static(
    '/actone',
    array(
        'controller' => 'cont',
        'action'     => 'actone'
    )
));
Adrian Schneider
You should use Zend_Controller_Router_Route_Static (http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.static) in this case to avoid firing up the regexp engine
Maxence
Right. This was just a quick example. I'll add it in to help the next person out.
Adrian Schneider
Also notable is the Jara static-route plugin (http://github.com/jara/jara-base/blob/master/library/Jara/Plugin/StaticRoutes.php).
David Weinraub