Skip to content

Instantly share code, notes, and snippets.

@evercode1
Created January 1, 2015 02:13
Show Gist options
  • Select an option

  • Save evercode1/e1f2abeb6dac685bdd00 to your computer and use it in GitHub Desktop.

Select an option

Save evercode1/e1f2abeb6dac685bdd00 to your computer and use it in GitHub Desktop.
actionUpdate Profile Controller Chap 8
public function actionUpdate()
{
if($model = Profile::find()->where(['user_id' => Yii::$app->user->identity->id])->one()) {
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view']);
} else {
return $this->render('update', [
'model' => $model,
]);
}
} else {
throw new NotFoundHttpException('No Such Profile.');
}
}
@tolgayilmaz86

Copy link
Copy Markdown

hi,
why we'd used redirect instead of render on line 8?

@namsir

namsir commented Nov 28, 2015

Copy link
Copy Markdown

redirect because you want user to go back to their profile page instead of rendering a new view to create another profile.

@farid-linein

Copy link
Copy Markdown

if($model = Profile::find()->where(['user_id' => Yii::$app->user->identity->id])->one()) { ... }
why use tenary operator for $model because $model does not have value yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment