vxm/yii2-js-params 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vxm/yii2-js-params

Composer 安装命令:

composer require vxm/yii2-js-params

包简介

Support passed variables to javascript.

README 文档

README

Latest Stable Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality Yii2

About it

An extension provide an easy way to passed variables from your server to the JavaScript in rendering process of Yii2 view component.

Requirements

Installation

Require Yii2 JS Prams using Composer:

composer require vxm/yii2-js-params

Usage

You can passed any variables you want when render view with addition jsParams element in view params:

use yii\web\Controller;

class TestController extends Controller
{

    public function actionTest()
    {
        return $this->render('test', [
            'jsParams' => [
                'test' => 'vxm'
            ]
        ]);
    }
}

And get this data on the frontend side from window.serverParams:

Note: all variables will passed at View::POS_HEAD please make sure a definition ($this->head()) on your layout file.

Global params

Sometime you need to passed some params to all of view file, you can config it in your app config file:

'components' => [
    'view' => [
        'params' => [
            'jsParams' => ['test' => 'vxm']
        ]
    ]
]

Or config an anonymous function:

'components' => [
    'view' => [
        'params' => [
            'jsParams' => function() {
            
                return ['identity' => Yii::$app->user->identity->toArray()]
            }
        ]
    ]
]

Now use it on client side:

<script>

    console.log(window.serverParams.identity);

</script>

统计信息

  • 总下载量: 75
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2019-04-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固