gintonicweb / requirejs
Requirejs helper for CakePHP
Installs: 825
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 2
Open Issues: 0
Type:cakephp-plugin
Requires
- php: >=5.4.16
- cakephp/cakephp: ~3.0
Requires (Dev)
- cakephp/cakephp-codesniffer: 2.*
- phpunit/phpunit: 4.1.*
This package is not auto-updated.
Last update: 2021-10-30 02:24:44 UTC
README
Require plugin for CakePHP
Load javascript modules (AMD) asynchroneously from anywhere in your views via requirejs.
Installation
Install the plugin using composer.
"gintonicweb/requirejs": "~0.2"
Load it in config/bootstrap.php
Plugin::load('Requirejs');
Example
Load this helper from your controller and define your config options.
require
the basepath where requirejs library can be found (optional)configFiles
requirejs configuration files (optional)inlineConfig
inline configuration options, echoed as an inline config file (optional)
public $helpers = [
'Requirejs.Require' => [
'require' => 'myrequire',
'configFiles' => [
'myconfig',
'Someplugin.config',
],
'inlineConfig' => [
'baseUrl' => '/',
'urlArgs' => 'bust=0',
],
],
];
Here's how load javascript modules. CakePHP plugin notation is supported. When
no plugins are defined, the module name is passed as-is to requirejs, allowing
you to handle the path the way you like in your own config.js
. Once in your
template, call load()
to load the requirejs lib. It's also possible
to pass an array of additional config modules to the load method if needed.
<?= $require->module('Requirejs.app/demo') ?>
<?= $require->module('test/demo') ?>
<?= $require->load() ?>