dongmin3754 2015-02-19 15:52
浏览 149
已采纳

Laravel控制器操作返回错误404

I'm getting a 404 error when trying to access a route linked to a controller action.

I have the route defined like this in my routes.php file.

Route::controller('error', 'ErrorsController');

The ErrorsController class looks as follows.

class ErrorsController extends BaseController {

    public function __construct()
    {
        // vacio
    }

    public function getIndex()
    {
        return View::make('error.accessdenied');
    }

    public function getAccessDenied()
    {
        return View::make('error.accessdenied');
    }
}

I have a view with a link to chek if it is working properly. The link is created as follows

{{ HTML::linkAction('ErrorsController@getAccessDenied', 'Error') }}

When I click on the link the page moves to the URL 'mytestdomain.com/error/access-denied' returning an 404 error, but when I access the URL 'mytestdomain.com/error' it works perfectly.

Any idea on what I'm doing wrong?

EDIT: Running the command php artisan routes these are the routes pointing to ErrorsController:

+--------+------------------------------------------------------------------------------------------------+------+--------------------------------------+----------------+---------------+
| Domain | URI                                                                                            | Name | Action                               | Before Filters | After Filters |
+--------+------------------------------------------------------------------------------------------------+------+--------------------------------------+----------------+---------------+
|        | GET|HEAD error/index/{one?}/{two?}/{three?}/{four?}/{five?}                                    |      | ErrorsController@getIndex            |                |               |
|        | GET|HEAD error                                                                                 |      | ErrorsController@getIndex            |                |               |
|        | GET|HEAD error/access-denied/{one?}/{two?}/{three?}/{four?}/{five?}                            |      | ErrorsController@getAccessDenied     |                |               |
|        | GET|HEAD|POST|PUT|PATCH|DELETE error/{_missing}                                                |      | ErrorsController@missingMethod       |                |               |
+--------+------------------------------------------------------------------------------------------------+------+--------------------------------------+----------------+---------------+

Only the sencond and the fourth ones are working.

  • 写回答

2条回答 默认 最新

  • douhuan5073 2015-02-26 10:58
    关注

    Somehow I found the problem.

    For some reason, my apache server doesn't rewrite mytestdomain.com/error/ * route. Probably is something related with the word error and the apache module mod_rewrite.

    Anyway, defining the route as follows solves the problem.

    Route::controller('fail', 'ErrorsController');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥50 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗