w3lifer / yii2-js-data-provider

1.0.1 2024-09-15 16:01 UTC

This package is auto-updated.

Last update: 2024-09-26 17:55:23 UTC


README

安装

composer require w3lifer/yii2-js-data-provider

用法

1. 创建 @app/controllers/JsDataProviderController

<?php

namespace app\controllers;

class JsDataProviderController extends \yii\web\Controller
{
    public function actionIndex(): string
    {
        return $this->render('index');
    }
}

2. 创建 @app/views/js-data-provider/index.php

<?php

/**
 * @see \app\controllers\JsDataProviderController::actionIndex()
 *
 * @var \yii\web\View $this
 *
 * @see https://:809/js-data-provider
 */

$this->title = 'JsDataProvider';

\w3lifer\Yii2\JsDataProvider::widget([
    'const' => 'MY_CONST',
    'data' => [
        'foo' => 'bar',
        'baz' => 'qux',
    ],
]);

3. 上述代码在 <head> 部分注册了以下JavaScript

<script>const MY_CONST={"foo":"bar","baz":"qux"}</script>