Skip to content

Commit

Permalink
Merge branch 'docs/view-helpers' of https://github.com/cgmartin/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Jul 5, 2012
2 parents bac1b64 + c11a67c commit 818e98f
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 1 deletion.
8 changes: 7 additions & 1 deletion documentation/manual/en/manual.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,12 @@
<xi:include href="../en/module_specs/Zend_I18n-Translating.xml" parse="xml"/>
</xi:fallback>
</xi:include>

<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="module_specs/zend.i18n.view.helpers.xml" parse="xml">
<xi:fallback>
<xi:include href="../en/module_specs/zend.i18n.view.helpers.xml" parse="xml"/>
</xi:fallback>
</xi:include>
</chapter>

<!--<chapter xml:id="zend.infocard"><title>Zend_InfoCard</title>-->
Expand Down Expand Up @@ -1994,7 +2000,7 @@

<chapter xml:id="zend.validator">
<title>Zend\Validator</title>

<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="module_specs/zend.validator.xml" parse="xml">
<xi:fallback>
<xi:include href="../en/module_specs/zend.validator.xml" parse="xml"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<section xmlns="http://docbook.org/ns/docbook" version="5.0" xml:id="zend.i18n.view.helper.currency-format"><title>CurrencyFormat Helper</title>

<para>
The <classname>CurrencyFormat</classname> view helper can be used to simplify rendering
of localized currency values. It acts as a wrapper for the <classname>NumberFormatter</classname>
class within the Internationalization extension (Intl).
</para>

<example xml:id="zend.i18n.view.helper.currency-format.usage"><title>Basic Usage of CurrencyFormat</title>
<programlisting language="php"><![CDATA[
// Within your view
echo $this->currencyFormat(1234.56, "USD", "en_US");
// This returns: '$1,234.56'
]]></programlisting>

<para>
<methodname>currencyFormat($number, $currencyCode, $locale)</methodname>
</para>

<itemizedlist>
<listitem>
<para>
<varname>$number</varname> : The numeric currency value.
</para>
</listitem>
<listitem>
<para>
<varname>$currencyCode</varname> : The 3-letter ISO 4217 currency code indicating the currency to use.
</para>
</listitem>
<listitem>
<para>
<varname>$locale</varname> : (Optional) Locale in which the number would be formatted (locale name, e.g. en_US).
If unset, it will use the default locale (<classname>Locale::getDefault()</classname>)
</para>
</listitem>
</itemizedlist>

</example>

<example xml:id="zend.i18n.view.helper.currency-format.setter-usage"><title>CurrencyFormat Setters</title>
<para>
The <varname>$currencyCode</varname> and <varname>$locale</varname> can be set prior to formatting
so that they are not required each time the helper is used:
</para>

<programlisting language="php"><![CDATA[
// Within your view
$this->plugin("currencyformat")->setCurrencyCode("USD")->setLocale("en_US");
echo $this->currencyFormat(1234.56); // "$1,234.56"
echo $this->currencyFormat(5678.90); // "$5,678.90"
$this->plugin("currencyformat")->setCurrencyCode("EUR");
echo $this->currencyFormat(1234.56); // "€1,234.56"
echo $this->currencyFormat(5678.90); // "€5,678.90"
]]></programlisting>

</example>
</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<section xmlns="http://docbook.org/ns/docbook" version="5.0" xml:id="zend.i18n.view.helper.number-format"><title>NumberFormat Helper</title>

<para>
The <classname>NumberFormat</classname> view helper can be used to simplify rendering
of locale-specific number and percentage strings.
It acts as a wrapper for the <classname>NumberFormatter</classname>
class within the Internationalization extension (Intl).
</para>

<example xml:id="zend.i18n.view.helper.number-format.usage"><title>Basic Usage of NumberFormat</title>
<programlisting language="php"><![CDATA[
// Within your view
echo $this->numberFormat(
1234567.891234567890000,
NumberFormatter::DECIMAL,
NumberFormatter::TYPE_DEFAULT,
"de_DE"
);
// This returns: '1.234.567,891'
]]></programlisting>

<para>
<methodname>numberFormat($number, $formatStyle, $formatType, $locale)</methodname>
</para>

<itemizedlist>
<listitem>
<para>
<varname>$number</varname> : The numeric value.
</para>
</listitem>
<listitem>
<para>
<varname>$formatStyle</varname> : (Optional) Style of the formatting, one of the format style constants.
If unset, it will use <varname>NumberFormatter::DECIMAL</varname> as the default style.
</para>
</listitem>
<listitem>
<para>
<varname>$formatType</varname> : (Optional) The formatting type to use. If unset, will use
<varname>NumberFormatter::TYPE_DEFAULT</varname> as the default type.
</para>
</listitem>
<listitem>
<para>
<varname>$locale</varname> : (Optional) Locale in which the number would be formatted (locale name, e.g. en_US).
If unset, it will use the default locale (<classname>Locale::getDefault()</classname>)
</para>
</listitem>
</itemizedlist>

</example>

<example xml:id="zend.i18n.view.helper.number-format.setter-usage"><title>NumberFormat Setters</title>
<para>
The <varname>$formatStyle</varname>, <varname>$formatType</varname>, and
<varname>$locale</varname> can be set prior to formatting
so that they are not required each time the helper is used:
</para>

<programlisting language="php"><![CDATA[
// Within your view
$this->plugin("numberformat")
->setFormatStyle(NumberFormatter::PERCENT)
->setFormatType(NumberFormatter::TYPE_DOUBLE)
->setLocale("en_US");
echo $this->numberFormat(0.56); // "56%"
echo $this->numberFormat(0.90); // "90%"
$this->plugin("numberformat")
->setLocale("de_DE");
echo $this->numberFormat(0.56); // "56 %"
echo $this->numberFormat(0.90); // "90 %"
]]></programlisting>

</example>
</section>
28 changes: 28 additions & 0 deletions documentation/manual/en/module_specs/zend.i18n.view.helpers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<section xmlns="http://docbook.org/ns/docbook" version="5.0"
xml:id="zend.view.helpers">
<title>I18n View Helpers</title>

<para>
In your view scripts, often it is necessary to perform certain complex functions over and
over: e.g., formatting a date, formatting currency, or displaying translated content. You can
use helper, or plugin, classes to perform these behaviors for you.
</para>

<para>
See the section on <link linkend="zend.view.helpers">view helpers</link> for more information.
</para>

<section xml:id="zend.view.helpers.initial">
<title>Included I18n Helpers</title>

<para>
Zend Framework comes with an initial set of helper classes related to Internationalization.
The currently shipped helpers include:
</para>

<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="zend.i18n.view.helper.currency-format.xml"/>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="zend.i18n.view.helper.number-format.xml"/>
</section>

</section>

0 comments on commit 818e98f

Please sign in to comment.