2017 © Pedro Peláez
 

library rdn-require-js

Zend Framework 2 RequireJS module

image

radnan/rdn-require-js

Zend Framework 2 RequireJS module

  • Sunday, February 16, 2014
  • by radnan
  • Repository
  • 1 Watchers
  • 1 Stars
  • 10,462 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

RdnRequireJS

The RdnRequireJS ZF2 module integrates the RequireJS library into your project., (*1)

How to install

  1. Use composer to require the radnan/rdn-require-js package:, (*2)

    $ composer require radnan/rdn-require-js:1.*
    
  2. Activate the module by including it in your application.config.php file:, (*3)

    ~~~php array( 'RdnRequireJS', // ... ), ); ~~~ ## How to use Create your **RequireJS** modules in your project's `public/` directory: ~~~js // public/Bar.js define(['./Foo'], function(Foo) { Foo.log('Hello World!'); }); ~~~ Then, in your view templates, call the `requireJS($name)` view helper with the module name as the argument: ~~~php /** @var Zend\View\Renderer\PhpRenderer $this */ requireJS('Bar') ?>, (*4)


The view helper will include the RequireJS library along with the requested modules as inline scripts. ### Multiple dependencies You can call the view helper multiple times and it will keep appending the module dependencies. You can also provide an array to include multiple deps at a time: ~~~php /** @var Zend\View\Renderer\PhpRenderer $this */ requireJS(['Bar', 'Baz']) ?>

Code completion

If you'd like to have code completion for this helper, include the following in your PhpRenderer class:, (*5)

namespace App\View\Renderer;

use Zend\View\Renderer\PhpRenderer as ZendPhpRenderer;

/**
 * @method requireJS(\string $dependencies = array())
 */
class PhpRenderer extends ZendPhpRenderer
{
}

Then, simply type hint the $this variable to this class in your view templates., (*6)

Library

The RequireJS library is, by default, included from cdnjs. You can configure this using the rdn_require_js.library option:, (*7)

<?php

return array(
    'rdn_require_js' => array(
        'library' => '/path/to/local/require.js',
    ),
);

This path should be relative to your project's base path. The view helper will use the basePath() view helper to resolve the full path., (*8)

Configuration

You can manage the default requireJS configuration using the rdn_require_js.config option:, (*9)

<?php

return array(
    'rdn_require_js' => array(
        'config' => array(
            'baseUrl' => '/modules',

            'paths' => array(
                'App' => 'app/js',
            ),

            'packages' => array(
                'App',
            ),
        ),
    ),
);

RequireJS config documentation, (*10)

The Versions

16/02 2014

dev-master

9999999-dev

Zend Framework 2 RequireJS module

  Sources   Download

MIT

The Requires

 

by Avatar radnan

zf2 zend requirejs

16/02 2014

v1.0.0

1.0.0.0

Zend Framework 2 RequireJS module

  Sources   Download

MIT

The Requires

 

by Avatar radnan

zf2 zend requirejs