dongyi2993 2014-01-01 19:14
浏览 29

用于uri路由的HTTP动词

I'm learning laravel, come from codeigniter. as we know, typically we declare http verb in routing in laravel.

Route:post(...)

Route::get(...);

my question is, not about laravel, what is the advantage(s) for grouping/creating route according to http verb like that ??

thanks.

  • 写回答

1条回答 默认 最新

  • dskvfdxgdo2422392 2014-01-01 19:52
    关注

    It allows you to use separate controller functions, one for post one for get, which stops repetitive if (isset($_POST['param'])) to check when you should and shouldn't be attempting to access the POSTed data and such.

    It also allows you to limit access to routes depending upon the method used to access them. For example I like to make all my ajax routes only available via. POST.

    You can use Route::any() to cover all methods if you don't want to separate access methods.

    On a site note, no idea if this has anything to do with why it was developed this way, but when being strict about unit testing, functions should be kept as short as possible, to a maximum of 10 lines in order to help keep code easily debug-able. Separating the access methods allows you to reduce the amount of lines within controller functions.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度