PHPackages                             phillaf/gtw\_require - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. phillaf/gtw\_require

ActiveCakephp-plugin[Framework](/categories/framework)

phillaf/gtw\_require
====================

Require.js plugin for CakePHP

124

Since Nov 9Pushed 12y ago1 watchersCompare

[ Source](https://github.com/Phillaf/GtwRequire)[ Packagist](https://packagist.org/packages/phillaf/gtw_require)[ RSS](/packages/phillaf-gtw-require/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Requirejs plugin for CakePHP
============================

[](#requirejs-plugin-for-cakephp)

This module facilitate the use of Requirejs through the Require helper.

- Modules can be added from views or view blocks
- Define your own config file, load modules according to your needs.
- Possibility of auto-loading modules based on action/controller names.

Installation
------------

[](#installation)

Copy this plugin in a folder named `app/Plugin/GtwRequire` or add these lines to your `composer.json` file :

```
{
    "require": {
        "phillaf/gtw_require": "*@dev"
    }
}

```

Create a symlink from this plugin's webroot to the application webroot by running `Console/cake symlink` or the lines below

```
# On windows
mklink /J app\webroot\GtwRequire app\Plugin\GtwRequire\webroot

# On linux
ln -s app/Plugin/GtwRequire/webroot app/webroot/GtwRequire

```

Load the plugin by adding this line to `app/Config/bootstrap.php`

```
CakePlugin::load('GtwRequire');

```

Add the Require helper to your AppController.php

```
public $helpers = array(
    'Require' => array('className' => 'GtwRequire.GtwRequire'),
);

```

Including javascript
--------------------

[](#including-javascript)

Create a config file as specified by requirejs. You can find a more exhaustive example [here](https://gist.github.com/Phillaf/7051827).

```
// app/webroot/js/config.js
requirejs.config({
    baseUrl: 'js/lib',
    paths: {
        app: '../app',
        basepath: '/GtwRequire/js/basepath' //application base path
    }
});

```

Load modules from your views, view blocks and elements using the req function.

```

```

Load the main requirejs module at the bottom of your layout file. The param is the path of your config file.

```

```

The `req()` function can only be called before `load()`. However, in some case like with ajax views, you'll need to add modules dynamically. For this you can use:

```

```

Path-specific includes
----------------------

[](#path-specific-includes)

If you want to auto-load action-specific or controller-specific files, you can create a folder structure like the one used in the Views.

```
├── lib
│   └── library1.js
│   └── library2.js
├── app
│   └── homemade1.js
│   └── homemade2.js
├── base
│   ├── Example /* folder containing ExampleController.php actions */
│   │   ├── someaction.js
│   │   ├── otheraction.js
│   ├── base.js
│   ├── ExampleController.js
│   ├── AnotherController.js
└── require.js

```

To enable auto-load, call the following function above your `load()` call. First param is the base path of your folder structure, second param is the name of the default file.

```

```

Application Base Path
---------------------

[](#application-base-path)

Sometimes you need to call controllers and actions from your javascript. In order to keep your .js module functionnal when websites are hosted on subdomains, use `basepath` to prefix your calls. Here's how modules can make use of this:--

```
require(['jquery','basepath'], function ($, basepath) {
    $('.something').click(function(){
        $.get( basepath+ "plugin_name/controller_name/action_name/", function(data){
            // do things
        });
    });
});

```

Copyright and license
---------------------

[](#copyright-and-license)

Author: Philippe Lafrance
Copyright 2013 [Gintonic Web](http://gintonicweb.com)
Licensed under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0.html)

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8abcc63bee5cff0754fe8d8251f6a61cffc21c46f96acd00a80c9cd307bbbbc0?d=identicon)[Phillaf](/maintainers/Phillaf)

---

Top Contributors

[![phillaf](https://avatars.githubusercontent.com/u/1533572?v=4)](https://github.com/phillaf "phillaf (15 commits)")

### Embed Badge

![Health badge](/badges/phillaf-gtw-require/health.svg)

```
[![Health](https://phpackages.com/badges/phillaf-gtw-require/health.svg)](https://phpackages.com/packages/phillaf-gtw-require)
```

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k104.3M836](/packages/laravel-socialite)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k38.6M289](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
