There is a method for updating the page with ajax.
public function actionUpdate( $id ) { $page = Page::find( $id )->one(); if ( Yii::$app->request->post() ) { $page->attributes = \Yii::$app->request->post('Page'); if ( $page->validate() && $page->save() ) { return $this->actionUpdate( $page->id ); } } if( $page !== null ) { if ( Yii::$app->request->isAjax ) { return $this->renderAjax( '_form', [ 'model' => $page ] ); } else { return $this->render( 'update', [ 'model' => $page ] ); } } else { throw new \yii\web\NotFoundHttpException('Page not found'); } }
After the update you need to stay on the edited page, updating the info. But the problem is that it goes into a cycle, i.e. I get something like recursion :(
return $this->renderAjax('_form')
orreturn ['success' => $page->save()];
- Alexey Shimanskyreturn $this->renderAjax('_form')
Although strange, return seems to be supposed to stop further script executionreturn $this->actionUpdate( $page->id );
And he chases him in a circle: ( - Guestreturn
is done, for examplereturn 2+3;
addition will be executed at the beginning ..... respectively, you always want to perform an action update at the beginning, and it doesn’t reachreturn
respectively - Alexei Shimansky