0
votes

I'm developing a web app with Zend Framework 2.

I want to achieve urls with current locale automatically built-in, i.e. /locale/controller/action/etc. I wrote this:

<?php

$locale = new Zend_Locale();

?>

<ul class="nav">
    <li>
        <a href="/<?php echo $locale->getLanguage(); ?>/devices">Devices</a>
        <ul>
            <li>
                <a href="/devices/add"><img src="img/navbar/add.png" alt="+"> Add</a>
            </li>
        </ul>
    </li>
    <li>
        <a href="/<?php echo $locale->getLanguage(); ?>/favorites">Favorites</a>
        <ul>
            <li>
                <a href="/favorites/add"><img src="img/navbar/add.png" alt="+"> Add</a>
            </li>
        </ul>
    </li>
</ul>

and put it in a navbar.phtml file that i include in this way

include("navbar.phtml");

in my Application/view/layout/layout.phtml.

But, i only get this

Fatal error: Class 'Zend_Locale' not found in blabla\module\Application\view\layout\navbar.phtml on line 3

What's wrong? I forget some "use"? Sorry but i'm a newbie in php.

2
Zend_Locale is a Zend1 method of localization. See: framework.zend.com/manual/2.2/en/index.html#zend-i18nnaththedeveloper
Thanks man! Get it :Dmaxdelia

2 Answers

1
votes

Installation of PHP intl extension is must.

0
votes

Ok, i just resolved.

The code above is relative to the older version of Zend Framework.

In Zend Framework 2 the right code is this:

<?php

$translator = new Zend\I18n\Translator\Translator();
$locale = substr($translator->getLocale(), 0, 2);

?>

<ul class="nav">
    <li>
        <a href="/<?php echo $locale ?>/devices">Devices</a>
        <ul>
            <li>
                <a href="/<?php echo $locale ?>/devices/add"><img src="img/navbar/add.png" alt="+"> Add</a>
            </li>
        </ul>
    </li>
    <li>
        <a href="/<?php echo $locale ?>/favorites">Favorites</a>
        <ul>
            <li>
                <a href="/<?php echo $locale ?>/favorites/add"><img src="img/navbar/add.png" alt="+"> Add</a>
            </li>
        </ul>
    </li>
</ul>

And don't forget to enable intl PHP extension!