Prev | Current Page 353 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

Unfortunately,
whilst we know which locale we want, strftime() uses the locale of the server unless you tell it otherwise.
There are two solutions: use setlocale() or Zend_Date.
Licensed to Menshu You
Zend Framework in Action (Ch01) Manning Publications Co. 47
At first glance, using setlocale() is very tempting; we just need to add setlocale(LC_TIME,
$lang); to our Language action helper. However it doesn??™t work as expected. The first problem with
setlocale() is that it is not thread-safe. This means that If you are using a threaded webserver, then you need to
call setlocale() before every use of a locale-aware PHP function. The second issue is that on Windows, the
string that is passed to the setlocale() function is not the same as the string we are using in our config.ini file.
That is, we are using ???de??? for German, however the Windows version of setlocale() expects ???deu???. Zend_Date,
as a member of the Zend Framework works more predictably for us.
Zend_Date is a class that comprehensively handles date and time manipulation and display. It is also
locale-aware and if you pass it a Zend_Locale object, it will use it to translate all date and time related strings.
Our immediate requirement is simply to retrieve dates in the correct format for the user, so we use
Zend_Date??™s get() function as shown in listing 14.


Pages:
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
matchbox sklep mieszkania szczecin 2 1 Paula Abdul produkcja