Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect route when route is more complex #2937

Closed
crustamet opened this issue May 5, 2020 · 4 comments
Closed

redirect route when route is more complex #2937

crustamet opened this issue May 5, 2020 · 4 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@crustamet
Copy link
Contributor

Hello i am trying to redirect to a reversed route specified in my routes like this and i get this error.
SYSTEMPATH/HTTP/Exceptions/HTTPException.php at line 146

Here is my routes


$routes->group('cms/banners', ['namespace' => 'App\Controllers\cms'], function($routes)
{
	$routes->get('/', 'banners::index');
	$routes->get('add', 'banners::add');
	$routes->get('edit/(:num)', 'banners::edit/$1');
	$routes->post('add', 'banners::submit_add');
});

And here is my code inside my controller
return redirect()->route('cms/banners/edit/'.$id_item);

When i submit the form i want to go to the edit page of the item.
It does not work.

When i go to the edit page of the item manually

https://example.com/cms/banners/edit/36
it works perfectly, the Route is working correctly.

@crustamet crustamet added the bug Verified issues on the current code behavior or pull requests that will fix them label May 5, 2020
@crustamet
Copy link
Contributor Author

I have tried also with the route_to function like this and it is still not working.
return redirect()->route(route_to('App\Controllers\cms\banners::edit', $id_item));

the route_to function returning the string '/cms/banners/edit/30'

but the redirect is not working

@vitnibel
Copy link

vitnibel commented May 6, 2020

This is not a bug.
This redirect option is used in the case of named routes.
Maybe another redirect option is right for you:
return redirect()->to('cms/banners/edit/'.$id_item);

@crustamet
Copy link
Contributor Author

I found how it should work with like i want,

i just had to put an alias for the route like this
$routes->get('edit/(:num)', 'banners::edit/$1', ['as' => 'edit_banner']);

and then use this in my controller
return redirect()->route('edit_banner', [$id_item]);

@crustamet
Copy link
Contributor Author

Dude, this redirect()->route() is amazing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

2 participants