Laravel 4 missingMethod返回空白页?

问题描述 投票:0回答:1

我正在使用laravel 4,并且在我的路线中有如下资源:

 Route::resource('admin/admins/actions', 'AdminActionsController');

我的AdminActionsController.php控制器具有missingMethod,如下所示:

    public function missingMethod($parameters = array())
{
 //show All Admin Users
return Redirect::to('admin/admins');
}

它假设每当缺少方法时都重定向到admin / admins,但是当我尝试类似admin / admins / actions / test之类的东西时,我得到了一个空白页? 有人知道为什么吗?

谢谢

php laravel laravel-4
1个回答
0
投票

如果您发现通用控制器在找不到任何功能时会给您的错误,您会发现它是

public function __call($method, $parameters)
{
    throw new \BadMethodCallException("Method [$method] does not exist.");
}

而不是missingMethod (即使在文档中说确实如此)

如果您覆盖__call函数,例如:

    public function __call($method,$parameters = array())
{
 //show All Admin Users
return Redirect::to('admin/admins');
}

它将按预期工作。

请记住,例如,如果有电话,例如:

admin/admins/actions/foobar

它不会给您丢失的函数,因为foobar被认为是$ id,它被传递给show($ id)函数。 如果您没有显示功能,那么只有它会提示您该功能缺失。

© www.soinside.com 2019 - 2024. All rights reserved.