w3lifer/yii2-js-data-provider

1.0.1 2024-09-15 16:01 UTC

This package is auto-updated.

Last update: 2024-10-26 18:17:32 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>