Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tutida/Pack
Cakephp3 variables in JS
https://github.com/tutida/Pack
cakephp cakephp3-variables
Last synced: 3 months ago
JSON representation
Cakephp3 variables in JS
- Host: GitHub
- URL: https://github.com/tutida/Pack
- Owner: tutida
- License: mit
- Created: 2016-07-22T13:33:44.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-08-27T13:01:29.000Z (about 4 years ago)
- Last Synced: 2024-07-17T01:03:48.204Z (4 months ago)
- Topics: cakephp, cakephp3-variables
- Language: PHP
- Size: 10.7 KB
- Stars: 10
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pack plugin is for CakePHP3
You can easy to pass CakePHP4 variables to JS in View.
## Requirements ##
* PHP >= 7.0
* CakePHP >= 4.0## Installation
In Application.php
```php
addPlugin('Pack');
```In controller.
```php
loadComponent('Pack.Pack');
}
...
}
```In layout php or template php.
```php
= $this->Pack->render();?>
```## Usage
Just set variables in your controller.
```
Hoge->get($id);
$array = [...];$this->Pack->set('entity', $entity);
$this->Pack->set('array', $array);## OR ##
$this->Pack->set(compact('entity', 'array'));```
Just get the variables in your JS in view.
```js
Pack.entity;
Pack.array;
```## Methods
1. set($varName, $variable) … Set variable in Pack.
2. remove($varNamee) … Remove variable in Pack.
3. show() … Show all variable in Pack.
4. rename($namespace) … Change Pack's namespace in JS.example
In controller
```php
$this->Pack->rename('Hoge');
$this->Pack->set('array', $array);
```In js
```js
Hoge.array;
```