spiral / app

Spiral Framework Skeleton HTTP Application: Queue, Console, Cycle ORM
https://spiral.dev/
MIT License
191 stars 20 forks source link

Redirect with data #24

Closed sujit-baniya closed 4 years ago

sujit-baniya commented 4 years ago

How would I redirect to URL with additional data, success message, errors?

wolfy-j commented 4 years ago

Use query params? We do not use redirected forms, check spiral/toolkit (Ajax forms). Thought we do not have many docs for it yet. But it will be documented with admin panel soon

sujit-baniya commented 4 years ago

Yes with query params! Use Case 1: When I try to login with invalid credentials, I should be redirected to login with errors

wolfy-j commented 4 years ago

Pass additional parameters into the Router->uri method. Second argument, docs are here: https://spiral.dev/docs/http-routing#url-generation

You can also modify the generated Uri object, see https://www.php-fig.org/psr/psr-7/

sujit-baniya commented 4 years ago

This is working:

$uri = $this->router->uri('login', [
    'error' => 'Invalid Users'
]);
return $this->response->redirect($uri);

It's a bit difficult... :)

sujit-baniya commented 4 years ago

Thanks @wolfy-j Closing it

wolfy-j commented 4 years ago

I'll show you later the proper way to do that. So you won't need to redirect anything like that.