Skip to content

Instantly share code, notes, and snippets.

@markdrake
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save markdrake/e8291ac9a7c336a0973d to your computer and use it in GitHub Desktop.

Select an option

Save markdrake/e8291ac9a7c336a0973d to your computer and use it in GitHub Desktop.

Revisions

  1. markdrake renamed this gist Jun 19, 2014. 1 changed file with 0 additions and 0 deletions.
  2. markdrake revised this gist Jun 19, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ZF2-view-helpers-in-classes
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    // This will allow you to use any view helper in any class such as a controller //
    // 1. Instantiate the view helper.
    // 2. Configure it.
  3. markdrake created this gist Jun 19, 2014.
    19 changes: 19 additions & 0 deletions ZF2-view-helpers-in-classes
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    // This will allow you to use any view helper in any class such as a controller //
    // 1. Instantiate the view helper.
    // 2. Configure it.
    // 3. Use it.

    // E.g. Use currency formatter
    $currencyFormatter = new CurrencyFormat();
    $currencyFormatter->setCurrencyCode('USD');
    $currencyFormatter->setLocale('en_US');

    $value = 10000;

    $formattedValue = $currencyFormatter($value);

    var_dump($formattedValue); // Will output $ 1,000 with HTML entities such as &nbsp;

    // When this example will be useful?
    // In a select element of a form, as the value options are automatically echoed by the formRow view helper
    // the currency format needs to be set when the value options are assigned.