modules/admin/controllers/AdminsController.php
/**
     * Creates a new Admins model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new Admins model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new Admins model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        if (\Yii::$app->user->can('CreateAdmin')) {
        $model = new Admins();
        $model->role = 'admin';
        if($model->load(Yii::$app->request->post())){
            $model->setPassword($model->password);
            $model->generateAuthKey();
        }
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $auth = Yii::$app->authManager;
            $role_admin = $auth->getRole('admin'); 
            $auth->assign($role_admin, $model->id);
            return $this->redirect(['view', 'id' => $model->id]);
        }
        return $this->render('create', [
            'model' => $model,
        ]);
        }else{
           Yii::$app->session->SetFlash('error','Недостаточно прав!');
           return $this->redirect('/');
        }
    }
public function actionCreate ( ) { if ( \ Yii :: $ app -> user -> can ( 'CreateAdmin' ) ) { $ model = new Admins ( ) ; $ model -> role = 'admin' ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { $ model -> setPassword ( $ model -> password ) ; $ model -> generateAuthKey ( ) ; } if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> save ( ) ) { $ auth = Yii :: $ app -> authManager ; $ role_admin = $ auth -> getRole ( 'admin' ) ; $ auth -> assign ( $ role_admin , $ model -> id ) ; return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; } else { Yii :: $ app -> session -> SetFlash ( 'error' , 'Недостаточно прав!'); return $ this -> redirect ( '/' ) ; } }
Creates a new Admins model.
Creates a new Admins model .
// Получаем роль admin