Chris,
These are not assumptions. This is my understanding after spending the last
two days reading
the Zend documentation (and every post I could find on the subject). Maybe
I am still new
enough to Zend not to be able to grasp the routing concepts or maybe they
just don't make
sense to me.
In either case I have exhausted the Zend documentation on this subject and
need some help
from others. I have tried what I believe to be "Route Chaining"
unsuccessfully. My
understanding of route chaining is that if one route does not match, go to
the next route. Here is
some sample code bits from my bootstrap.php that show what I have tried
unsuccessfully with
chains (keep in mind the current order of these routes is insignificant
since I have tried them in
every order possible):
self::$router = self::$frontController->getRouter();
$route = new Zend_Controller_Router_Route(
'/:module',
array('module' => ':module',
'controller' => 'index',
'action' => 'index')
);
self::$router->addRoute('module', $route);
$route = new Zend_Controller_Router_Route(
'/:module/:controller',
array('action' => 'index'));
self::$router->addRoute('controller', $route);
$route = new Zend_Controller_Router_Route(
'/:module/:action',
array('module'=>'default', 'controller'=>'index',
'action'=>'index'));
self::$router->addRoute('action', $route);
Now my understanding from the documentation is that these routes are added
to a chain in
order. If the first route that is checked does not match it goes to the
next route. Here is how I
thought the above code should work.
If I type in host.com/modulename, it finds the module. If I type in
host.com/modulename
/controllername I get "Action "controllername" does not exist and was not
trapped in __call() "
but if I type in host.com/modulename/index/actionname it works.
Now if I put the action route above the controller route (under the module
route), the following
works: host.com/modulename, host.com/modulename/controllername,
host.com/modulename
/controllername/actionname or host.com/modulename/index/actionname. This
surprises me
because I thought the order of this route chain was module -> action ->
controller, which to me
means that if I type in host.com/modulename/controllername I should get an
error that the
controllername is not a valid action.
What I am trying to achieve here is to be able to type
host.com/modulename/actionname and for
the route controller to first check for a controller called "actionname"
and if it does not exist,
look in the indexcontroller for action "actionname".
So if you can shed some light on how route chains are defined and used and
possibly share an
example of how I could achieve the above, that would be great.
Aside from that if I need to overwrite the standard router, I can do that
but as I mentioned
before I am not sure how to do this.
David
Chris Weldon wrote:
>
> David,
>
> I think you need to disavow the assumptions in terms of how things are
> routed and write your own routes for things you need. This will help
> reduce confusion on how to specify requests from the URL.
> Documentation on how to do this can be found on the same page:
>
> http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes
>
> You can make it cleaner by defining routes in an XML config file. But,
> the short of it is continue reading and you'll get a better idea of
> how to implement routes in ZF.
> --
> Chris Weldon
>
>
> On Wed, Feb 4, 2009 at 10:56 AM, dbroderick
> <[email protected]> wrote:
>>
>> using ZF 1.7.3 and module/controller/action configuration
>>
>> The current default routing behavior in Zend Framework is as stated in
>> the
>> documentation:
>>
>> "10.5.4. Default routes
>>
>> Zend_Controller_Router_Rewrite comes preconfigured with a default route,
>> which will match URIs in the shape of controller/action. Additionally, a
>> module name may be specified as the first path element, allowing URIs of
>> the
>> form module/controller/action. Finally, it will also match any additional
>> parameters appended to the URI by default -
>> controller/action/var1/value1/var2/value2."
>>
>> So if I navigate to a module name that does not exist, the router will
>> automatically look for a controller of the same name, if it finds a
>> controller with that name it will serve it. I have two requests:
>>
>> 1. Zend extends that functionality to controllers and actions. If I
>> navigate to a controller name that does not exist, the default router
>> will
>> automatically look for an action of that same name in the index
>> controller.
>>
>> This would effectively remove the need to put 'index' (controler) in the
>> URI.
>>
>> 2. Being somewhat new to ZF, I would like some guidence on how to extend
>> or
>> customize the current default router to accomplish this.
>>
>> David
>> --
>> View this message in context:
>> http://www.nabble.com/Zend-Framework-Routing-tp21834663p21834663.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Christopher Weldon
> http://chrisweldon.net
> [email protected]
>
>
--
View this message in context:
http://www.nabble.com/Zend-Framework-Routing-tp21834663p21840417.html
Sent from the Zend Framework mailing list archive at Nabble.com.