Yii2 的问题解决方案

yii2 Class 'app\controllers\AccessControl' not found

一般是命名空间问题, 写成\yii\filters\AccessControl::className(),

yii2想要新增第三方vendor, 修改composer.json, 

"require-dev": {

        "yiisoft/yii2-codeception": "*",

        "yiisoft/yii2-debug": "*",

        "yiisoft/yii2-gii": "*",

        "zircote/swagger-php": "*",

        "yiisoft/yii2-faker": "*"

    },

 加入了"zircote/swagger-php": "*", 然后运行php composer.phar update发现报错

于是找到解决方案

php composer.phar global require "fxp/composer-asset-plugin:~1.1.1"

然后在php composer.phar update, 不再报错

表单提交改成Ajax形式验证

Controller

if (Yii::$app->request->isAjax) {

            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

            return \yii\bootstrap\ActiveForm::validate($model);

}

View

$form = ActiveForm::begin([

        'enableAjaxValidation' => true,

    ]);

Activeform 下拉菜单多选

dropdownList(User::getArrayNoticeTargets(), ['multiple' => 'true', 'size' => 3])

Activeform 生成form是label和input平行样式

use yii\widgets\ActiveForm;
$form = ActiveForm::begin([
'options' => ['class' => 'form-horizontal'],
                'fieldConfig' => [
                    'template' => "{label}{input}\n{error}",
                    'labelOptions' => ['class' => 'col-md-4'],
                    'inputOptions' => ['class' => 'col-md-6'],
                ],
])


use yii\bootstrap\ActiveForm;
$form = ActiveForm::begin([

'layout' => 'horizontal',
'fieldConfig' => [ 'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}", 'horizontalCssClasses' => [ 'label' => 'col-sm-4', 'offset' => 'col-sm-offset-4', 'wrapper' => 'col-sm-8', 'error' => '', 'hint' => '', ], ] ])

Yii 的详细介绍请点这里
Yii 的下载地址请点这里

猜你喜欢

转载自www.linuxidc.com/Linux/2017-01/139315.htm
今日推荐