Ad

Octobercms, Redirect To Home From Component Not Working

- 1 answer

i'm trying to redirect from component if id from slug is wrong.

Running from layout

function onBeforePageStart(){ $this->Contentloader->getMeta(); }

In component i have:

public function getMeta(){

//id checking logic goes here

if ($id == null) return Redirect::to('/'); }

Inspecting the dd(Redirect::to('/')) object I see

enter image description here

But it's not redirecting.

Please advice

Thanks

Ad

Answer

try this

in your component :

public function getMeta()
{
   if ($id == null) return false;
}

in your layout :

function onBeforePageStart()
{ 
     $meta = $this->Contentloader->getMeta();
     if(!$meta)
          return Redirect::to('/');

}

I hope help you :)

Ad
source: stackoverflow.com
Ad