This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

rick.harrison [gatenbysanderson]
rick.harrison [gatenbysanderson]

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.

KurtJensen
KurtJensen

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

octoberAdam
octoberAdam

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

Sebastiaan Kloos (ICTBelang)
Sebastiaan Kloos (ICTBelang)

I have the same problem. Can anyone help us with this?

KurtJensen
KurtJensen

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

Sebastiaan Kloos (ICTBelang)
genuineq
genuineq

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

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.