This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello!
I'm writing a custom component, but as part of it under certain conditions I need to be able to force a redirect. I'd seen the documentation here about the component/page lifecycle:
https://octobercms.com/docs/plugin/components#page-cycle-handlers
and got the impression I should be able to :
return \Redirect::to('/my-url/');
within the onRun() method of the component, but it seems to have no effect - the page just loads as normal even when just doing:
public function onRun() { return \Redirect::to('/my-url/'); }
i've also tried it in the init() function too, to no avail. Any idea what i'm missing?
Cheers, Rick.
Make sure your redirect URL actually exists or it may be ignored.
The docs ( https://octobercms.com/docs/services/response-view#redirects ) give you some examples.
Try adding this to top of component
use Redirect;
Then test by putting this in onRun()
return Redirect::to('/');
Last updated
I've got exactly the same problem. Troubleshooting this I added :
use Redirect; use Backend\Classes\Controller;
to the component but no redirect occuring.
Last updated
Here is a working example in the code written by daftspunk ( one of the primary October developers ).
https://github.com/rainlab/user-plugin/blob/master/components/Account.php#L216
I had the same problem and one of the things I noticed is that redirects towards static pages DON'T work.
1-7 of 7