Issues

ZF-5679: Zend_Controller_Router_Route_Hostname - parameters doesn`t persist

Description

I find a problem while i was trying to use Zend_Controller_Router_Route_Hostname with a Language plugin, using the route to put the parameter ";language" into a subdomain.

  • Route via Zend_Config

routes.language_default.type = "Zend_Controller_Router_Route_Hostname" routes.language_default.route = ":language.localhost" routes.language_default.defaults.module = "public" routes.language_default.defaults.controller = "index" routes.language_default.defaults.action = "index" routes.language_default.defaults.language = "www" routes.language_default.reqs.language = "(?!www$).*"

when i type;

http://en.localhost/

seems not to be problems, but if i uso an other router like:

  • Route via Zend_Config

routes.contact.type = "Zend_Controller_Router_Route_Static" routes.contact.route = "contact" routes.contact.defaults.module = "public" routes.contact.defaults.controller = "contact" routes.contact.defaults.action = "index"

http://en.localhost/contact

the parameter of the subdomain persist in the url, but when i try to request the language from my language plugin didn`t return anything;

  • In the language plugin:

if (!$language = $request->getParam('language', false)) { $language = $locale->getLanguage(); }

it`s returning a (1) false parameter.

Comments

I could be wrong, but could it be, that you simply didn't chain the static route with the hostname route (as the example shows in the manual)?

Hi Ben yes i though it could be... but.. i tryed by an other way because i could not make it chain via config.ini..

$languageRoute = new Zend_Controller_Router_Route_Hostname( ':language.localhost', array( 'module' => 'public' ) );

    $defaultroute = new Zend_Controller_Router_Route_Static(
        '',
        array(
            'controller' => 'index', 
            'action' => 'index'
            )
        );
    $router->addRoute('default', $languageRoute->chain($defaultroute));

           $contactroute = new Zend_Controller_Router_Route_Static(
        'contact',
        array(
            'controller' => 'contact', 
            'action' => 'index'
            )
        );
    $router->addRoute('contact', $languageRoute->chain($contactroute));

ass you can see, it is chained, but there is still a problem, i don`t know if this is the way it is spected to work.. but to make it work i needed to add this lines to my language plugin

    $router = Zend_Registry::get('router');
    $router->setGlobalParam('language', $language);

    Zend_Registry::set('router', $router);

i think could be better if the hostname parameters persist as a global parameter throw the chained routes, what you think about it?

I don't see this as an issue, as every chained route exists for it alone, at least at the moment. Tho that will change with the refactoring for 2.0.

Is this still an issue? If so, can you provide some additional information on your language plugin? The language parameter from the hostname route will only be passed along to routes which are chained to it, and can then be retrieved through the router object's {{getParam}} method. Without seeing how you're trying to access that parameter through your language plugin we can't help.