歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

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' => '', ], ] ])

在Yii2中使用Pjax導致Yii2內聯腳本載入失敗的問題 http://www.linuxidc.com/Linux/2016-03/128949.htm

Yii2 實現修改密碼功能 http://www.linuxidc.com/Linux/2015-07/120137.htm

Yii 用戶登陸機制  http://www.linuxidc.com/Linux/2015-01/111602.htm

Yii中引入js和css文件  http://www.linuxidc.com/Linux/2015-01/111603.htm

Yii 不完全解決方案  http://www.linuxidc.com/Linux/2015-01/111606.htm

Yii CGridView 基本使用 http://www.linuxidc.com/Linux/2015-01/111607.htm

Yii框架分布式緩存的實現方案 http://www.linuxidc.com/Linux/2015-02/113828.htm

Yii 的詳細介紹:請點這裡
Yii 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved