Tuesday
12
January
2010

Currencies within the view

Today the last missing sheep of my new Zend_Currency implementation has been moved to core.

It’s the view helper for currencies which was missing.
Zend_View_Helper_Currency

Together with the new Zend_Currency implementation it simplifies rendering for all using currencies within their application. Let’s take a short look into an working example…

// Bootstrap
$currency = new Zend_Currency(array('value' => 100, 'locale' => 'fr_FR'));
Zend_Registry::set('Zend_Currency', $currency);

We prepared our currency to be used application wide.
Now the view:

// View
$this->currency();

This would output “100,00 €” (or something related).
Really simple, isn’t it ?

Of course this would not work when you have multiple currencies which you are working with.
Then you must work with other registry keys and give the wished instance.

// Model
$instance_1 = new Zend_Currency(array('value' => 100, 'locale' => 'fr_FR'));
$instance_2 = new Zend_Currency(array('value' => 500, 'locale' => 'en_US'));

And in the view:

// View
$this->currency($instance_1);
$this->currency($instance_2);

Please look into the manual for further informations.
There’s nothing more to say than enjoy my new currency implementation for Zend Framework. ;-)

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top