ZF Custom Router

4 messages Options
Embed this post
Permalink
Flirt4

ZF Custom Router

Reply Threaded More More options
Print post
Permalink
Hello all!
I`m new to zend, and I have some difficult with zend router. I have site + admin area on zend framework. Now i need to add some languages to my site. I do it and all is ok, now my router in bootstrap.php look like this :

$route = new Zend_Controller_Router_Route(
                        ':module/:lang/:controller/:action/*',
                                        array('controller'=>'index',
                                                'action' => 'index',
                                                'module'=>'default',
                                                'lang'=>$lang));

                $front     = Zend_Controller_Front::getInstance();
                $router = $front->getRouter();
          $router->addRoute ( 'default', $route );
                $front->setRouter($router);

Now all is working fine but there are one think that i dont like - in my site all links including "default" - module text. http://localhost/default/en/products/index/cat/16 . And when i go to the admin - http://localhost/admin/en/add/products/ . I don`t want in my site to include default module text "default" and I don`t need languages param in admin area( i need to be like this http://localhost/en/products/index/cat/16 and for admin - http://localhost/admin/add/products/ ) . Can somebody help me to resolve this? Thank you in advance!
prodigitalson

Re: ZF Custom Router

Reply Threaded More More options
Print post
Permalink
Just add another route.. but take care they are you add them in order (most general -> most specific):

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

$admin = new Zend_Controller_Router_Route(
                        'admin/:controller/:action/*',
                                        array('controller'=>'index',
                                                'action' => 'index',
                                                'module'=>'admin',
                                                ));

$front     = Zend_Controller_Front::getInstance();
                $router = $front->getRouter();
          $router->addRoutes ( array('default' => $default, 'admin' => $admin );
                $front->setRouter($router);

Flirt4 wrote:
Hello all!
I`m new to zend, and I have some difficult with zend router. I have site + admin area on zend framework. Now i need to add some languages to my site. I do it and all is ok, now my router in bootstrap.php look like this :

$route = new Zend_Controller_Router_Route(
                        ':module/:lang/:controller/:action/*',
                                        array('controller'=>'index',
                                                'action' => 'index',
                                                'module'=>'default',
                                                'lang'=>$lang));

                $front     = Zend_Controller_Front::getInstance();
                $router = $front->getRouter();
          $router->addRoute ( 'default', $route );
                $front->setRouter($router);

Now all is working fine but there are one think that i dont like - in my site all links including "default" - module text. http://localhost/default/en/products/index/cat/16 . And when i go to the admin - http://localhost/admin/en/add/products/ . I don`t want in my site to include default module text "default" and I don`t need languages param in admin area( i need to be like this http://localhost/en/products/index/cat/16 and for admin - http://localhost/admin/add/products/ ) . Can somebody help me to resolve this? Thank you in advance!
dmitrybelyakov

Re: ZF Custom Router

Reply Threaded More More options
Print post
Permalink

prodigitalson wrote:
Just add another route.. but take care they are you add them in order (most general -> most specific):

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

$admin = new Zend_Controller_Router_Route(
                        'admin/:controller/:action/*',
                                        array('controller'=>'index',
                                                'action' => 'index',
                                                'module'=>'admin',
                                                ));

$front     = Zend_Controller_Front::getInstance();
                $router = $front->getRouter();
          $router->addRoutes ( array('default' => $default, 'admin' => $admin );
                $front->setRouter($router);
Thats indeed a better/simpler solution.
Flirt4

Re: ZF Custom Router

Reply Threaded More More options
Print post
Permalink
Hi,

its work exellent! Tanks prodigitalson ! My mistake was in routes order.