w3lifer / yii2-js-data-provider
Installs: 612
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: ^8.0
- yiisoft/yii2: ^2.0
This package is auto-updated.
Last update: 2024-12-26 18:37:38 UTC
README
Installation
composer require w3lifer/yii2-js-data-provider
Usage
1. Create @app/controllers/JsDataProviderController
:
<?php namespace app\controllers; class JsDataProviderController extends \yii\web\Controller { public function actionIndex(): string { return $this->render('index'); } }
2. Create @app/views/js-data-provider/index.php
:
<?php /** * @see \app\controllers\JsDataProviderController::actionIndex() * * @var \yii\web\View $this * * @see http://localhost:809/js-data-provider */ $this->title = 'JsDataProvider'; \w3lifer\Yii2\JsDataProvider::widget([ 'const' => 'MY_CONST', 'data' => [ 'foo' => 'bar', 'baz' => 'qux', ], ]);
3. The code above registers the following JavaScript in the <head>
section:
<script>const MY_CONST={"foo":"bar","baz":"qux"}</script>