controllers/TodoController.php
/**
     * Creates a new Todo model.
     * For ajax request will return json object
     * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new Todo model.
For ajax request will return json object
and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new Todo model . For ajax request will return json object and for non - ajax request if creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $request = Yii::$app->request;
        $model = new Todo();  
        if($request->isAjax){
            Yii::$app->response->format = Response::FORMAT_JSON;
            if($request->isGet){
                return [
                    'title'=> "Create new Todo",
                    'content'=>$this->renderAjax('create', [
                        'model' => $model,
                    ]),
                    'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"]).
                                Html::button('Save',['class'=>'btn btn-primary','type'=>"submit"])
                ];         
            }else if($model->load($request->post()) && $model->save()){
                return [
                    'forceReload'=>'#crud-datatable-pjax',
                    'title'=> "Create new Todo",
                    'content'=>'<span class="text-success">Create Todo success</span>',
                    'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"]).
                            Html::a('Create More',['create'],['class'=>'btn btn-primary','role'=>'modal-remote'])
                ];         
            }else{           
                return [
                    'title'=> "Create new Todo",
                    'content'=>$this->renderAjax('create', [
                        'model' => $model,
                    ]),
                    'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"]).
                                Html::button('Save',['class'=>'btn btn-primary','type'=>"submit"])
                ];         
            }
        }else{
            if ($model->load($request->post()) && $model->save()) {
                return $this->redirect(['view', 'id' => $model->id]);
            } else {
                return $this->render('create', [
                    'model' => $model,
                ]);
            }
        }
    }
public function actionCreate ( ) { $ request = Yii :: $ app -> request ; $ model = new Todo ( ) ; if ( $ request -> isAjax ) { Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; if ( $ request -> isGet ) { return [ 'title' => " Create new Todo " , 'content' => $ this -> renderAjax ( 'create' , [ 'model' => $ model , ] ) , 'footer' => Html :: button ( 'Close' , [ 'class' => 'btn btn-default pull-left' , 'data-dismiss' => " modal " ] ) . Html :: button ( 'Save' , [ 'class' => 'btn btn-primary' , 'type' => " submit " ] ) ] ; } else if ( $ model -> load ( $ request -> post ( ) ) && $ model -> save ( ) ) { return [ 'forceReload' => '#crud-datatable-pjax' , 'title' => " Create new Todo " , 'content' => '<span class="text-success">Create Todo success</span>' , 'footer' => Html :: button ( 'Close' , [ 'class' => 'btn btn-default pull-left' , 'data-dismiss' => " modal " ] ) . Html :: a ( 'Create More' , [ 'create' ] , [ 'class' => 'btn btn-primary' , 'role' => 'modal-remote' ] ) ] ; } else { return [ 'title' => " Create new Todo " , 'content' => $ this -> renderAjax ( 'create' , [ 'model' => $ model , ] ) , 'footer' => Html :: button ( 'Close' , [ 'class' => 'btn btn-default pull-left' , 'data-dismiss' => " modal " ] ) . Html :: button ( 'Save' , [ 'class' => 'btn btn-primary' , 'type' => " submit " ] ) ] ; } } else { if ( $ model -> load ( $ request -> post ( ) ) && $ model -> save ( ) ) { return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } else { return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; } } }
Creates a new Todo model.
Creates a new Todo model .
/*
            *   Process for ajax request
            */ /*
            *   Process for non-ajax request
            */