public function beforeSave($insert) { if (!parent::beforeSave($insert)) { return false; } $this->name = strtolower(Pinyin::pinyin($this->real_title)) . '_' . uniqid(); return true; }
/** * @name 角色用户分配列表 */ public function actionUser($id) { $auth = Yii::$app->authManager; $users = User::find()->where(['status' => 10])->andWhere('id>1')->orderBy('username')->all(); $users_info = []; foreach ($users as $k => $v) { $pin = strtoupper(substr(Pinyin::pinyin($v['username']), 0, 1)); $users_info[$pin][$v['id']] = ['username' => $v['username'], 'pinyin' => Pinyin::pinyin($v['username']), 'is_sel' => $auth->getAssignment($id, $v['id']) ? 1 : 0]; } $keys = array_keys($users_info); return $this->render('user', ['user' => $users_info, 'keys' => $keys, 'role_name' => $id]); }
/** * @name 编辑权限组 * If update is successful, the browser will be redirected to the 'view' page. * @param string $id * @return mixed */ public function actionUpdate($id) { $this->layout = '@backend/views/layouts/form'; $model = $this->findModel($id); if ($model->load(Yii::$app->request->post())) { $model->name = strtolower(Pinyin::pinyin($model->real_title)) . '_' . uniqid(); if ($model->save()) { return $this->redirect(['index']); } } return $this->render('update', ['model' => $model]); }