public function actionCreate()
    {
        /** @var \amnah\yii2\user\models\User $user */
        /** @var \amnah\yii2\user\models\Profile $profile */

        $user = $this->module->model("User");
        $user->setScenario("admin");
        $profile = $this->module->model("Profile");

        $post = Yii::$app->request->post();
        $userLoaded = $user->load($post);
        $profile->load($post);

        // validate for ajax request
        if (Yii::$app->request->isAjax) {
            Yii::$app->response->format = Response::FORMAT_JSON;
            return ActiveForm::validate($user, $profile);
        }

        if ($userLoaded && $user->validate() && $profile->validate()) {
            $user->save(false);
            $profile->setUser($user->id)->save(false);
            return $this->redirect(['view', 'id' => $user->id]);
        }

        // render
        return $this->render('create', compact('user', 'profile'));
    }
public function actionCreate()
    {
        /** @var \amnah\yii2\user\models\User $user */
        /** @var \amnah\yii2\user\models\Profile $profile */

        $user = $this->module->model("User");
        $user->setScenario("admin");
        $profile = $this->module->model("Profile");

        $post = Yii::$app->request->post();
        $userLoaded = $user->load($post);
        $profile->load($post);

        // validate for ajax request
        if (Yii::$app->request->isAjax) {
            Yii::$app->response->format = Response::FORMAT_JSON;
            return ActiveForm::validate($user, $profile);
        }

        if ($userLoaded && $user->validate() && $profile->validate()) {
            $user->save(false);
            $profile->setUser($user->id)->save(false);
            return $this->redirect(['view', 'id' => $user->id]);
        }

        // render
        return $this->render('create', compact('user', 'profile'));
    }
public function actionCreate ( ) { /** @var \amnah\yii2\user\models\User $user */ /** @var \amnah\yii2\user\models\Profile $profile */ $ user = $ this -> module -> model ( "User" ) ; $ user -> setScenario ( "admin" ) ; $ profile = $ this -> module -> model ( "Profile" ) ; $ post = Yii :: $ app -> request -> post ( ) ; $ userLoaded = $ user -> load ( $ post ) ; $ profile -> load ( $ post ) ; // validate for ajax request if ( Yii :: $ app -> request -> isAjax ) { Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; return ActiveForm :: validate ( $ user , $ profile ) ; } if ( $ userLoaded && $ user -> validate ( ) && $ profile -> validate ( ) ) { $ user -> save ( false ) ; $ profile -> setUser ( $ user -> id ) -> save ( false ) ; return $ this -> redirect ( [ 'view' , 'id' => $ user -> id ] ) ; } // render return $ this -> render ( 'create' , compact ( 'user' , 'profile' ) ) ; }
Create a new User model. If creation is successful, the browser will
be redirected to the 'view' page.
@return mixed
Create a new User model . If creation is successful the browser will be redirected to the view page .