prawee/yii2-widgets

yii2 widgets 警报

安装数: 1,483

依赖者: 0

建议者: 0

安全性: 0

星星: 2

关注者: 2

分支: 5

公开问题: 0

类型:yii2-extension

1.0.0 2019-07-21 07:54 UTC

This package is auto-updated.

Last update: 2024-09-23 15:59:42 UTC


README

视图上所有小部件类的扩展类

包含

  • ButtonAjax:用于创建显示模态框的Ajax按钮
  • LinkAjax:用于创建显示模态框的Ajax链接

安装

安装此扩展的首选方式是通过 Composer

运行以下命令之一:

php composer.phar require --prefer-dist prawee/yii2-widgets "dev-master"

或将以下内容添加到您的 composer.json 文件的 require 部分中:

"prawee/yii2-widgets": "dev-master"

使用方法

ButtonAjax | LinkAjax

在您的视图中

use prawee\widgets\ButtonAjax;
use yii\bootstrap\Modal;

echo ButtonAjax::widget([
    'name'=>'Create',
    'route'=>['create'],
    'modalId'=>'#main-modal',
    'modalContent'=>'#main-content-modal',
    'options'=>[
        'class'=>'btn btn-success',
        'title'=>'Button for create application',
    ]
]);
...
Modal::begin(['id'=>'main-modal']);
echo '<div id="main-content-modal"></div>';
Modal::end();

在您的控制器中

public functionn actionCreate(){
    ...
    if(Yii::$app->getRequest()->isAjax){
        return $this->renderAjax('create', [
            'model' => $model,
        ]);
    }else{
        return $this->render('create', [
            'model' => $model,
        ]);
    }
}