<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use yii\helpers\Url; use backend\models\AuthCategory; /* @var $this yii\web\View */ /* @var $model backend\models\AuthRole */ /* @var $form yii\widgets\ActiveForm */ $cate = ArrayHelper::map(AuthCategory::find()->all(), 'id', 'name'); ?> <div class="auth-role-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'description')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'cat_id', ['template' => "{label}\n<div class='input-group auth-cate'>{input}<span class=\"input-group-addon\"><i class=\"fa fa-plus\"></i></span></div> \n{hint}\n{error}"])->dropDownList($cate, ['prompt' => '请选择分类']); ?> <?php echo $form->field($model, 'rules')->textInput(['maxlength' => true]); ?> <?php
public function getAuthCategory() { return $this->hasOne(AuthCategory::className(), ['id' => 'cat_id']); }
public function actionCategoryEdit($id) { $model = AuthCategory::findOne($id); //$model->findOne($id); $response = Yii::$app->response; $result['success'] = 0; if ($model->load(Yii::$app->request->post()) && $model->save()) { if (Yii::$app->request->isAjax) { $result = ['success' => 1]; $response->format = $response::FORMAT_JSON; return $result; } else { //return $this->redirect(['view', 'id' => $model->id]); } } return $result; }
/** * Creates a new AuthRole model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreateCate() { $model = new AuthCategory(); $response = Yii::$app->response; if ($model->load(Yii::$app->request->post()) && $model->save()) { if (Yii::$app->request->isAjax) { $id = $model->id; $data = $model->find()->asArray()->all(); $result = ['selected' => $id, 'data' => $data]; $response->format = $response::FORMAT_JSON; return $result; } else { return $this->redirect(['view', 'id' => $model->id]); } } else { if (Yii::$app->request->isAjax) { $response->format = $response::FORMAT_JSON; return $model->getErrors(); } return $this->render('create', ['model' => $model]); } }