Hi!
Im trying to redirect back to a form, if the form fails.
In my route
i have the following
$app->get('/edit/{id:[0-9]+}', 'HomeController:getEditCrud')->setName('view');
And that route looks like:
/**
* @return view with post
*/
public function getEditCrud(Request $request, Response $response, $args){
$query = $this->pdo->from('notes')->where('note_id', $args['id'])->fetch();
return $this->view->render($response, 'edit-crud.twig', ['query' => $query]);
}
And if i want to make a URL to this page, I use <a href="{{ path_for('view', {id: query.note_id}) }}">edit</a>
If i exclude , {id: query.note_id}
i will receive error Message: An exception has been thrown during the rendering of a template ("Missing data for URL segment: id") in "crud.twig" at line 33.
I resevice (almost) the same error when trying ti redirect back to the page where this forms is.
if ($validation->failed())
{
$this->flash->addMessage('warning', 'Please fill all fields.');
return $response->withRedirect($this->router->pathFor('view'));
}
I get error:
Type: InvalidArgumentException
Message: Missing data for URL segment: id
Question
So my question is, how do i add the ID segment when redirecting?