Question

I'm trying to implement route chaining for an admin panel on a Zend Framework site that I am working on. I'm using the following configuration file in hopes that the "admin" route routes with "/admin" and that the "adminLogin" route routes with "/admin/login".

<?xml version="1.0" encoding="UTF-8"?>
<routes>
    <admin>
        <route>admin</route>
        <defaults>
            <module>admin</module>
            <controller>index</controller>
            <action>index</action>
        </defaults>
        <chains>
            <adminLogin>
                <route>login</route>
                <defaults>
                    <module>admin</module>
                    <controller>login</controller>
                    <action>index</action>
                </defaults>
            </adminLogin>
        </chains>
    </admin>
</routes>

With that configuration though, only "adminLogin" works. The route "admin" routes to the default module/controller/action.

I think that I must be missing something with how chaining works. Any feedback greatly appreciated

Was it helpful?

Solution

The parent route of a chain (in this case, admin) will not actually match like a real route. Its sole purpose it the catch the top level match, then let its chained children handle the actual routing.

Try explicitly adding an empty static route to the top of your chain, like so:

<chains>
    <index type="Zend_Controller_Router_Route_Static">
        <route></route>
        <defaults module="admin" controller="index" action="index" />
    </index>
    <login>
        <route>login</route>
        <defaults>
                <module>admin</module>
                <controller>login</controller>
                <action>index</action>
        </defaults>
    </login>
</chains>

See an older answer of mine for some more details and gotchas of chained routes.

Also, it is worth noting the that router automatically concatenates chained route names with a dash, so, if you ever need to use your login route explicitly, it would currently be named admin-adminLogin. I would recommend renaming it to simply login.

OTHER TIPS

This might not work any more, because of a bug. There is a workaround though.

http://framework.zend.com/issues/browse/ZF-7848

This is the wrong use of chains.

Just declare a route for /admin, and a different one for /admin/login. Chains are more useful if you're using more than one route class to determine the resolution of one route (like hostname and path).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top