ijackua/yii2-gon Push data from PHP controller to JS variable (inspired by https://github.com/gazay/gon)

extensionjavascript

yii2-gon

Latest Version on Packagist Software License Total Downloads

Push data from PHP controller to global JS variable (inspired by https://github.com/gazay/gon)

Install

Via Composer

$ composer require ijackua/yii2-gon

Configure

Add component to application config

'components' => array(
    'gon' => 'ijackua\gon\GonComponent'
),

And to app bootstrap section

$config = array(
    'bootstrap' => array('gon'),
    ...

Full component configuration example

'components' => array(
       'gon' => array(
            'class' => 'ijackua\gon\GonComponent',
            'jsVariableName' => 'gon',
            'globalData' => ['g1' => 1, 'g2' => '2'],
            'showEmptyVar' => true,
        )
),

Usage

Anywhere in your app push key -> value

\Yii::$app->gon->push('someObj', ['a'=>'b']);
\Yii::$app->gon->push('str', 'hello');

On JS side you will get

> window.gon
>> Object
      someObj: Object
         {
           a: "b"
         }
      str: "hello"

TODO

  • Make optional non-global usage. AMD, CommonJS modules.

Change log

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Changelog

Changelog

All Notable changes to ijackua/yii2-gon will be documented in this file

NEXT - YYYY-MM-DD

Added

  • Nothing

Deprecated

  • Nothing

Fixed

  • Nothing

Removed

  • Nothing

Security

  • Nothing

2015-10-14

Added

  • Initial codebase

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



1.0.0 is the latest of one release



MIT license
Stats
8 github stars & 0 github forks
0 downloads in the last day
0 downloads in the last 30 days
6165 total downloads