PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

ZF Locale-Aware Classes

In the Zend Framework, locale-aware classes rely on Zend_Locale to automatically select a locale, as explained above. For example, in a Zend Framework web application, constructing a date using Zend_Date without specifying a locale results in an object with a locale based on information provided by the current user's web browser.

Example 543. Dates default to correct locale of web users

<?php
$date 
= new Zend_Date('2006',Zend_Date::YEAR);

To override this default behavior, and force locale-aware Zend Framework components to use specific locales, regardless of the origin of your website visitors, explicitly specify a locale as the third argument to the constructor.

Example 544. Overriding default locale selection

<?php
$usLocale 
= new Zend_Locale('en_US');
$date = new Zend_Date('2006'Zend_Date::YEAR$usLocale);
$temp = new Zend_Measure_Temperature('100,10',
                                     
Zend_Measure::TEMPERATURE,
                                     
$usLocale);

If you know many objects should all use the same default locale, explicitly specify the default locale to avoid the overhead of each object determining the default locale.

Example 545. Performance optimization when using a default locale

<?php
$locale 
= new Zend_Locale();
$date = new Zend_Date('2006'Zend_Date::YEAR$locale);
$temp = new Zend_Measure_Temperature('100,10',
                                     
Zend_Measure::TEMPERATURE,
                                     
$locale);

Zend Framework