dev-master
9999999-devYii2 widget to register JS into view
MIT
The Requires
by Richard Fan
extension yii2 javascript widget
v0.0.1
0.0.1.0Yii2 widget to register JS into view
MIT
The Requires
by Richard Fan
extension yii2 javascript widget
Wallogit.com
2017 © Pedro Peláez
Yii2 widget to register JS into view
Yii2 widget to register JS into view, (*2)
In Yii2, the way to register JS script into view is using \yii\web\View::registerJS(),, (*3)
For example, if you want to initialize a jQuery plugin, you do:, (*4)
// in view fileregisterJS('$(".modal").modal({backdrop:"static",keyboard:"false"})'); ?>Hello World!, (*5)
Obviously, this is a very bad way because:, (*6)
This widget help you register JS script in Yii just as you write script block directly into HTML!, (*7)
Install with Composer:, (*8)
composer require richardfan1126/yii2-js-register "*"
or, (*9)
php composer.phar require richardfan1126/yii2-js-register "*"
or add, (*10)
"richardfan1126/yii2-js-register":"*"
to the require section of your composer.json file., (*11)
In your view file, wrap your JS script with <script> tag, and wrap all the things with this widget., (*12)
example:, (*13)
// in view file use richardfan\widget\JSRegister;Hello World!, (*14)
IMPORTANT Remember not to add anything out of the <script> block., (*15)
There are 2 configurations for this widget, which are the parameters passed into \yii\web\View::registerJS() method. example:, (*16)
<?php JSRegister::begin([
'key' => 'bootstrap-modal',
'position' => \yii\web\View::POS_READY
]); ?>
<script>
// JS script
</script>
<?php JSRegister::end(); ?>
Yii2 widget to register JS into view
MIT
extension yii2 javascript widget
Yii2 widget to register JS into view
MIT
extension yii2 javascript widget