I cant get this to work.
I'm doing a post to a controller action. From that action I'm doing a lot of validations, db insert, file uploads etc.
Coming from Laravel Im used to is doing like this: (example with no real variables or methods. Just for visual presentation)
if(!$something->success){
return redirect("controller-url")->withErrors([$model->errors]);
}
// Next steps...
From what I can read in the docs Craft recommend posting to the same page to handle errors and pass the model down to the view, but then doing a page refresh will do the same again so I dont like that.
My Controller is like this :
Index (Renders index template)
public function actionIndex()
{
$this->renderTemplate("plugin/settings");
}
Post
public function actionPost()
{
if(!$model->validate()){
Craft::$app->getSession()->setError($message);
return $this->redirect("url-to-index-action");
}
}
So the setError() works fine but I want to the pass all the errors from the model to the index action after a redirect and then down to the twig template. How?