2017 © Pedro Peláez
 

yii2-extension yii2-gon

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

image

ijackua/yii2-gon

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

  • Monday, December 7, 2015
  • by iJackUA
  • Repository
  • 1 Watchers
  • 7 Stars
  • 3,109 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 5 % Grown

The README.md

yii2-gon

Latest Version on Packagist ![Software License][ico-license] Total Downloads, (*1)

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

Install

Via Composer, (*3)

$ composer require ijackua/yii2-gon

Configure

Add component to application config, (*4)

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

And to app bootstrap section, (*5)

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

Full component configuration example, (*6)

'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, (*7)

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

On JS side you will get, (*8)

> 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., (*9)

Contributing

Please see CONTRIBUTING for details., (*10)

Credits

License

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

The Versions

07/12 2015

dev-master

9999999-dev https://github.com/iJackUA/yii2-gon

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

  Sources   Download

MIT

The Requires

 

extension javascript yii

06/12 2015

1.0.0

1.0.0.0 https://github.com/iJackUA/yii2-gon

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

  Sources   Download

MIT

The Requires

 

extension javascript yii