modules/admin/controllers/SubAdminController.php
/**
     * Creates a new SubAdmin model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return string|\yii\web\Response
     * @throws \yii\base\Exception
     */
Creates a new SubAdmin model.
If creation is successful, the browser will be redirected to the 'view' page.
Creates a new SubAdmin model . If creation is successful the browser will be redirected to the ' view ' page .
public function actionCreate()
    {
        $model = new SubAdmin();
        $model->scenario = SubAdmin::SCENARIO_CREATE;
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            $password = $model->password;
            $model->user_type = (string)User::USER_TYPE_SUB_ADMIN;
            $model->password_hash = \Yii::$app->security->generatePasswordHash($model->password);
            if ($model->save()) {
                Yii::$app->session->setFlash(Growl::TYPE_SUCCESS, "Sub admin created successfully.");
                if (!empty($model->email)) {
                    try {
                        Yii::$app->mailer->compose('admin/subAdminRegistration-html', ['model' => $model, 'pwd' => $password])
                            ->setFrom([Yii::$app->params['adminEmail'] => Yii::$app->name])
                            ->setTo($model->email)
                            ->setSubject('Thank you for Registration!')
                            ->send();
                    } catch (HttpException $e) {
                        echo "Error: " . $e->getMessage();
                    }
                }
            } else {
                Yii::$app->session->setFlash(Growl::TYPE_DANGER, "Error while creating sub admin.");
            }
            return $this->redirect(['index']);
        }
        return $this->render('create', [
            'model' => $model,
        ]);
    }
public function actionCreate ( ) { $ model = new SubAdmin ( ) ; $ model -> scenario = SubAdmin :: SCENARIO_CREATE ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> validate ( ) ) { $ password = $ model -> password ; $ model -> user_type = ( string ) User :: USER_TYPE_SUB_ADMIN ; $ model -> password_hash = \ Yii :: $ app -> security -> generatePasswordHash ( $ model -> password ) ; if ( $ model -> save ( ) ) { Yii :: $ app -> session -> setFlash ( Growl :: TYPE_SUCCESS , " Sub admin created successfully. " ) ; if ( ! empty ( $ model -> email ) ) { try { Yii :: $ app -> mailer -> compose ( 'admin/subAdminRegistration-html' , [ 'model' => $ model , 'pwd' => $ password ] ) -> setFrom ( [ Yii :: $ app -> params [ 'adminEmail' ] => Yii :: $ app -> name ] ) -> setTo ( $ model -> email ) -> setSubject ( 'Thank you for Registration!' ) -> send ( ) ; } catch ( HttpException $ e ) { echo " Error:  " . $ e -> getMessage ( ) ; } } } else { Yii :: $ app -> session -> setFlash ( Growl :: TYPE_DANGER , " Error while creating sub admin. " ) ; } return $ this -> redirect ( [ 'index' ] ) ; } return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; }
Creates a new SubAdmin model.
Creates a new SubAdmin model .
//email for sub-admin credentials