Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-11-2008, 03:25 PM
Junior Member
 
Join Date: Apr 2008
Posts: 2
Default Localized SEO routing....

Hello,

I am quite new to the Zend Framework so I apologize in advance if I figured/assume things wrong

I work for a SEO company and they want me to use URLs with the following format:
Quote:
http://www.domain.com/languagecode/controller/action
i.e.:
Quote:
http://www.domain.com/fr/register
has to route to controller fr and action index.

However, the normal routing still has to work (i.e.:
Quote:
http://www.domain.com/register
)

Therefore, I did the following routing in my bootstrap:

PHP Code:
$router $frontController->getRouter(); /* @var $router Zend_Controller_Router_Rewrite */
//$router->addConfig($config->routes);
$route = new Zend_Controller_Router_Route(':lang/:controller/:action'
                                            
, array('module' => 'index',
                                                    
'controller' => 'index',
                                                    
'action' => 'index',
                                                    
'lang' => 'en'));
$router->addRoute('lang'$route); 
Now, I'd like to set a global variable which would detect the 'lang' param...

What would be the best way to do this ? I want this to be global and dont want to do the same thing in all my controllers... thats why i want to do it in bootstrap.

1) What is the best way to do this?
2) Is there any better solution you guys would have to suggest?
3) In my route, is there a way to add an optional module param ? i.e: :lang/:module/:controller/:action ... See if the module exists, otherwise, it is considered as a controller, and controller is considered like the action

THX A LOT IN ADVANCE

Last edited by sysk : 04-11-2008 at 03:27 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 04:10 PM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 119
Default

First of all, don't make controllers based on language. You'll end up repeating all the code for each language. The most gracefull solution I know of is to replace the default route with a new one. So instead of the router routing [:module]/:controller/:action/* you want it to route :lang/[:module]/:controller/:action/*.

This can be done in the bootstrap something like this:
Code:
$frontController = Zend_Controller_Front::getInstance();
.
.
.
$defaultRoute = new Zend_Controller_Router_Route(
                                     ':lang/:module/:controller/:action/*',
                                     array('lang' => 'en', //sets default if lang is not specified
                                            'module' => 'default'));

$router = $frontController->getRouter();
$router->removeDefaultRoutes()
       ->addRoute('default',$defaultRoute);
.
.
.
$frontController->dispatch();
* note I did not test this route you might have to monkey with it to get it to work, but the theory is sound and documented by Zend.

This way you'll end up with a param called lang that is available via getParam() and normal routing otherwise. You can then key of the lang param and implement internationalization as normal.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-15-2008, 12:17 PM
Junior Member
 
Join Date: Apr 2008
Location: The zombie room,Romania
Posts: 7
Send a message via Yahoo to americanu197
Default Anybody care to elaborate about using getParam

Cause for me it doesn't work and i can't make heads or tails of the docs.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-15-2008, 04:55 PM
Senior Member
 
Join Date: Jan 2008
Location: chicago
Posts: 101
Default

Quote:
Originally Posted by americanu197 View Post
Cause for me it doesn't work and i can't make heads or tails of the docs.

In an Action() function:
PHP Code:
$id $this->_request->getParam('id'); 
This post is Off Topic though.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-15-2008, 09:36 PM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 119
Default

Make a controller plugin that Registers the lang param in the registry or go ahead and declare a global. You should really examine your design before you go making globals tho. General rule of thumb is to not make globals unless they really really really need to be globals.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:20 AM.