在Laravel中使用自动控制器路线是个坏主意 [英] Use automatic controller routes in Laravel is a bad idea

查看:87
本文介绍了在Laravel中使用自动控制器路线是个坏主意的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要从CodeIgniter到Laravel.

I'm coming From CodeIgniter to Laravel.

那么,使用到所有控制器的自动路由是一个坏主意吗?

So, is a bad idea using automatic routes to all of controllers?

Route::controller(Controller::detect());

我应该用它代替在route.php中创建路由吗?

Should I use this instead creating routes in routes.php?

推荐答案

是的,这很不好.

Laravel 4中实际上不存在Controller :: detect(),因为它有点破损.

Controller::detect() is actually not present in Laravel 4 because it is a bit broken.

detect()将遍历您的文件系统并返回控制器文件,但这不是一个好主意,因为您定义路线的顺序很重要.如果您有任何嵌套的控制器,您会发现此中断很容易.

detect() will go through your filesystem and return controller files, but this is a bad idea because the order you define your routes matters. If you have any nested controllers you will find this breaking very easily.

detect()还将根据文件系统以不同的顺序返回文件,因此这导致很多不可预测性.

detect() will also return files in a different order depending on the file system, so this leads to a lot of unpredictability.

我认为您应该以任何方式定义所有路由,这使它的读取和调试更加容易.

I would argue that you should define all your routes any ways, it is a lot easier to read and debug.

这篇关于在Laravel中使用自动控制器路线是个坏主意的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆