renanbr/view-variables-zf-module

Assign variables to the view through configuration files in Zend Framework

dev-master / 2.0.x-dev 2013-09-20 18:25 UTC

This package is auto-updated.

Last update: 2020-10-05 10:03:35 UTC


README

Build Status Dependency Status

Assign variables to the view through configuration files in your Zend Framework application.

Usage

Set variables in the configuration files config/autoload/{,*.}{global,local}.php.

return array(
    // ...
    'view_variables' => array(
        'analytics_id' => 'UA-XXXXX-X',
        'app_version' => '4.2.0',
    ),
);

Then you can read them in view scripts...

<html>
    <head>
      <script type="text/javascript">
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', '<?php echo $this->escapeJs($this->analytics_id); ?>']);
        _gaq.push(['_trackPageview']);
        (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();
      </script>
    </head>
    <body>
        <h1>Hello there!</h1>
        <p>I'm a layout.</p>
        <?php echo $this->content; ?>
        <p>Application version: <?php echo $this->escapeHtml($this->app_version); ?></p>
    </body>
</html>

Installation

  1. Add renanbr/view-variables-zf-module dependency using Composer.

    php composer.phar require renanbr/view-variables-zf-module:~2

    Or change composer.json file...

    {
        "require": {
            "renanbr/view-variables-zf-module": "~2"
        }
    }

    For Composer documentation, please refer to getcomposer.org.

  2. Setup config/application.config.php file.

    return array(
        'modules' => array(
            // ...
            'RenanBrViewVariables', // <-- Add this line
        ),
        // ...
    );

    For Zend Framework modules documentation, please refer to framework.zend.com/manual.