如果来自子弹的ID错误,我正在尝试从组件重定向。
从布局运行
function onBeforePageStart(){ $this->Contentloader->getMeta(); }
在组件中,我有:
public function getMeta(){
//id checking logic goes here
if ($id == null) return Redirect::to('/'); }
检查我看到的dd(Redirect :: to('/'))对象
但是它没有重定向。
请咨询
谢谢
答案 0 :(得分:1)
尝试
在您的组件中:
public function getMeta()
{
if ($id == null) return false;
}
在您的布局中:
function onBeforePageStart()
{
$meta = $this->Contentloader->getMeta();
if(!$meta)
return Redirect::to('/');
}
希望对您有所帮助:)
答案 1 :(得分:0)
组件应能够处理重定向而无需使用onBeforePageStart()
。这只是一个简单的例子。在这里,我正在检查组件字段是否为空。如果为null,则返回到'/'。
您可以在组件中执行此操作:确保使用Redirect类use Redirect;
public function defineProperties()
{
return [
'useSomething' => [
'title' => 'Something',
'description' => 'Testing Testing',
'default' => '',
'type' => 'text',
]
];
}
public function onRun()
{
if ($this->property('useSomething') == null) {
return Redirect::to('/');
} else {
$this->page['something'] = $this->property('useSomething');
}
}