2

1) I have a controller "calendar" and have action "showDate" which gets date via url. So, url is something like "calendar/show-date/date/2012-07-22"

2) I have a link to display all entries, "calendar/"

So, I want to create routes so my links look like "kalendar/2012-07-22" and "kalendar/".

Can anyone help me?

Ivan Bajalovic
  • 780
  • 1
  • 9
  • 20

4 Answers4

2

According to this post: http://www.z-f.fr/forum/viewtopic.php?id=5138

The solution is to add '@locale' => $lang to the params.

$this->url(array('lang'=>'it','@locale'=>'it'))

It works very well for me.

SequenceDigitale.com
  • 4,038
  • 1
  • 24
  • 23
1

I've been looking into translating the URL with Zend_Translate and I came across this sites' plugin that attempts to auto-translate URL segments (module/controller/action).

http://blog.helmich.cz/305-howto-simple-multilingual-routes-in-zend-framework/

The nice thing is that it's a modified custom router class that can function similar to Zend_Router so it's relatively familiar off the bat.

$pages = new MyApp_Controller_Router_Route(
    ':locale/:@controller/:@action/*',
    array(
        'controller' =>; 'index',
                'action'     => 'index',
                'locale'     => 'cs'
            )
);

$router->addRoute('pages',$pages);

The thing you'll need is to have a language ID in your URL (called :locale in the above example) so your Zend_Translate can set the proper language.

www.example.com/en/calendar/2012-06-22/
www.example.com/fr/calendrier/2012-06-22/
www.example.com/de/kalender/2012-06-22/
www.example.com/it/calendario/2012-06-22/

I've only slightly played around with this concept but I recall that it had promise. You'll have to get more familiar with Zend_Translate: http://framework.zend.com/manual/en/zend.translate.html

I hope that helps!

Cheers!

jmbertucci
  • 8,194
  • 4
  • 50
  • 46
0

You could re-route all calls of calendar to kalendar. There are two possibilites, either you do it with Zend (preferable) or you change your webserver configuration to rewrite calls to calendar with a HTTP 302 (ugly).

You should however consult the official Zend Documentation, which is pretty good

0

You have to setup custom routes, this is my way:

in folder application/configs/ create file named "routes.ini"

Put in file your route:

;index-homepage, parameter date isn't required
;"index" is key of your route
routes.index.route = "kalendar/:date" 
routes.index.defaults.controller = calendar
routes.index.defaults.action = show
routes.index.defaults.date =

So in your bootstrap.php define that config file:

protected function _initRoute() {
    $router = Zend_Controller_Front::getInstance()->getRouter();
    $router->addDefaultRoutes();

    $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini');
    $router->addConfig($config, 'routes');
}

And that's it, you can call URL

www.website.com/kalendar

and

www.website.com/kalendar/2012-1-1

See answers in this question for details: Simple rewrites in Zend Framework

Community
  • 1
  • 1
tasmaniski
  • 4,767
  • 3
  • 33
  • 65
  • This is what you want in action dogadjaji.rs/kalendar-dogadjaja and dogadjaji.rs/kalendar-dogadjaja/10/2012 :) – tasmaniski Jun 22 '12 at 12:28
  • this does not match www.website.com/kalendar, it opens my showDate action with start_date param set to empty string – Ivan Bajalovic Jun 22 '12 at 12:42
  • try to setup show-date, instead of showDate... I update my Answer. You need to ask in controller if($_GET['start_date']){ ... } ... ofcourse – tasmaniski Jun 22 '12 at 12:43
  • routes.index-homepage.route = "kalendar/" routes.index-homepage.defaults.module = frontend routes.index-homepage.defaults.controller = calendar routes.index-homepage.defaults.action = index routes.index.route = "kalendar/:start_date" routes.index.defaults.module = frontend routes.index.defaults.controller = calendar routes.index.defaults.action = show routes.index.defaults.start_date = This is my routes.ini and it allways opens showAction in calendar controller, from both /kalendar and /kalendar/2012-07-01 .. For first link should open index action and for second showAction.. – Ivan Bajalovic Jun 22 '12 at 12:48
  • this also would disable any other /kalendar/:action route that I would like to add. I suppose there should be something like /kalendar/([0-9\-]+)/ to point to showAction and /kalendar/:action to point to someAction.. – Ivan Bajalovic Jun 22 '12 at 12:49
  • If you want to have two different action, for second route setup routes.index.route = "kalendar/start_date" (without :), and you can setup regexp routes.index.defaults.start_date = "([0-9\-]+)", everything else looks OK in your comment below. – tasmaniski Jun 22 '12 at 12:57