public function actionCreate($parent = null)
    {
        $model = new Area();
        if (!is_null($parent)) {
            $parent = Area::findOne(['id' => $parent]);
            if ($parent) {
                $model->parent = $parent->id;
                $model->parent_name = $parent->name;
            }
        }
        if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
            Yii::$app->response->format = Response::FORMAT_JSON;
            return ActiveForm::validate($model);
        }
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            Yii::$app->getSession()->setFlash('success', Yii::t('system','Create success.'));
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }
public function actionCreate($parent = null)
    {
        $model = new Area();
        if (!is_null($parent)) {
            $parent = Area::findOne(['id' => $parent]);
            if ($parent) {
                $model->parent = $parent->id;
                $model->parent_name = $parent->name;
            }
        }
        if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
            Yii::$app->response->format = Response::FORMAT_JSON;
            return ActiveForm::validate($model);
        }
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            Yii::$app->getSession()->setFlash('success', Yii::t('system','Create success.'));
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }
public function actionCreate ( $ parent = null ) { $ model = new Area ( ) ; if ( ! is_null ( $ parent ) ) { $ parent = Area :: findOne ( [ 'id' => $ parent ] ) ; if ( $ parent ) { $ model -> parent = $ parent -> id ; $ model -> parent_name = $ parent -> name ; } } if ( Yii :: $ app -> request -> isAjax && $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; return ActiveForm :: validate ( $ model ) ; } if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> save ( ) ) { Yii :: $ app -> getSession ( ) -> setFlash ( 'success' , Yii :: t ( 'system' , 'Create success.' ) ) ; return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } else { return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; } }
Creates a new Area model.
If creation is successful, the browser will be redirected to the 'view' page.
@param int|null $parent 父地区ID
@return mixed
Creates a new Area model . If creation is successful the browser will be redirected to the view page .