Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7563787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:45:15+00:00 2026-05-30T13:45:15+00:00

I’ve read all posts about routing and Zend Documentation but I still can’t solve

  • 0

I’ve read all posts about routing and Zend Documentation but I still can’t solve this issue.

I have a multi-language application with two modules: default and admin. The language selection is working fine (in a Controller routeShutdown Plugin), but I have some problems configuring the router:

I want to have these URL working:

/
/controller
/controller/action
/action                  (default controller)
/controller/param        (default action)
/admin
/admin/admin-controller
/admin/admin-controller/action

and using the language selector it would be:

/en
/en/controller
/en/controller/action
/en/action                  (default controller)
/en/controller/param        (default action)
/en/admin/admin-controller
/en/admin/admin-controller/action

I added this to my bootstap file (index.php):

$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$router->removeDefaultRoutes();
$router->addRoute('langmodcontrolleraction',

new Zend_Controller_Router_Route('/:lang/:module/:controller/:action',
    array('lang' => ':lang'))
);

$router->addRoute('langmodcontroller',
new Zend_Controller_Router_Route('/:lang/:module/:controller',
    array('lang' => ':lang',
        'action' => 'index'))
);

$router->addRoute('langmod',
new Zend_Controller_Router_Route('/:lang/:module',
    array('lang' => ':lang',
        'action' => 'index',
        'controller' => 'index'))
);

$router->addRoute('lang',
new Zend_Controller_Router_Route('/:lang',
    array('lang' => ':lang',
        'action' => 'index',
        'controller' => 'index',
        'module' => 'default'))
);

$frontController->setControllerDirectory(array(
'default'=>BASE_PATH.'app/modules/default/controllers',
'admin'=>BASE_PATH.'app/modules/admin/controllers'));    

In order to check how the router is parsing the URL, I added a var_dump to the routeShutdown plugin:

Entering to /en, I get:

array
'lang' => string 'en' (length=2)
'action' => string 'index' (length=5)
'controller' => string 'index' (length=5)
'module' => string 'default' (length=7)

which is OK. But when I enter to /en/controller1 I get:

array
'lang' => string 'en' (length=2)
'module' => string 'controller1' (length=8)
'action' => string 'index' (length=5)
'controller' => string 'index' (length=5) 

It is setting module to “controller1”. How can I tell the router to set the default value to the module? And for an URL like /en/controller/param? (setting module and action to default)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:45:16+00:00Added an answer on May 30, 2026 at 1:45 pm

    I’m afraid you’re going to need to rethink your URL scheme a little, or change the way your routes are setup, as you’ve hit two limitations of the way ZF’s routing works.

    The first is that the router has no knowledge of what is or isn’t a valid module, controller or action; all it does is match the strings in the URL to variables in the route. It does this by checking each route in succession, in reverse order, until it finds a match. When you hit /en/controller, it first checks your /:lang route, which won’t match. It then checks /:lang/:module, which will match, because /:lang/:module will match /anything/anything unless you tell it otherwise.

    With that in mind you won’t be able to have both:

    /en/controller
    /en/action
    

    unless you set some restrictions, as a URL like /en/foo will always be matched by whichever of the two you define last.

    If you have a fairly small number of actions/controllers that don’t often change, the simplest way around this is to hardcode in some possible values for the 2nd of the two routes, e.g.:

    $router->addRoute('langmod', new Zend_Controller_Router_Route(
        '/:lang/:module', 
        array(
            'lang' => ':lang',
            'action' => 'index',
            'controller' => 'index'
        ),
        array(
            'module' => '(foo|bar|something)'
        )
    ));
    

    replace foo, bar etc. with valid module names. Now when you hit /en/controller1 it won’t match this route because controller1 doesn’t match the regexp pattern defined for the :module variable. You would then need a separate /:lang/:controller route (or possibly /:lang/:controller/:action) for it to match instead.

    You asked how you set a default value for some of the variables. You are actually already doing this with the action in a few of your routes, but for controller/module won’t quite work in the way you are hoping. If we take your langmodcontroller route and change it to this:

    $router->addRoute('langmodcontroller',new Zend_Controller_Router_Route(
        '/:lang/:module/:controller',
        array(
            'lang' => ':lang',
            'controller' => 'index'
            'action' => 'index' 
        )
    ));
    

    there’s now a default value for the controller variable. If we pretend for a second that this was the only route, a request for /en/blog would now get matched by this and set the request params to lang = en, module = blog, controller = index, action = index. /en/blog/index/foo would also match this route, and would give you module = blog, controller = index, action = foo. But note that even though controller = index you still need that in the URL. So limitation number two is that you always need the variable in the URL (even if it is set to your default) as long as you have something after it that isn’t the default.

    With these limitations in mind I’d suggest you go with something like this (defined in this order):

    /:lang/:controller/:action/ (with 'index' defaults for controller and action)
    /:lang/:action (with 'action' restricted to some predefined values)
    /:lang/admin/:controller/:action (with 'admin' as a string in the URL, and :module set to 'admin' as the default)
    

    This would give you URLs like this:

    /en
    /en/controller
    /en/controller/action
    /en/action
    /en/controller/param
    /en/admin/controller
    /en/admin/controller/action
    

    which is pretty much what you are after.

    The routing in ZF is very powerful, you just need to know its quirks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a bunch of posts stored in text files formatted in yaml/textile (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.