【问题标题】:How does Laravel route::controller handle camel/snake case?Laravel route::controller 如何处理骆驼/蛇案?
【发布时间】:2013-05-26 07:05:52
【问题描述】:

在 routes.php 中:

Route::controller('account', 'AccountController');    

在 ajax -> 控制器中:

POST /account/password_reset -> postPasswordReset  //not working
POST /account/passwordReset -> postPasswordReset  //not working
POST /account/password_reset -> postPassword_reset  //not working
POST /account/passwordreset -> postPasswordreset  //working

我对第一个选项有印象(并且更喜欢),但它对我来说不是那样的。这里应该发生什么?

【问题讨论】:

  • 你试过用php artisan route检查你的路线吗?
  • 不确定如何使用它,但听起来很棒。我的服务器上收到了Command "route" is not defined.
  • 啊,我猜只需要更新我的 laravel 到 4.0.0
  • 我知道这是一个老问题,但是对于任何来这里的人来说,使用上面提到的 artisan 的 route 命令感到困惑,语法是:php artisan route:list

标签: routing laravel camelcasing


【解决方案1】:

Laravel 4 使用 - 分隔长动作名称,因此在这种情况下,您的动作如下所示

public function postPasswordReset

你的网址看起来像

/account/password-reset

但是,我建议使用内置的路由器 URL 帮助程序之一,例如 HTML::linkAction()URL::action(),或者如果您使用的是表单,只需指定 'action' => 'YourController@YourAction'

文档:http://laravel.com/docs/html#opening-a-form

【讨论】:

    猜你喜欢
    • 2021-03-31
    • 2022-06-21
    • 2019-10-30
    • 2020-11-19
    • 2020-02-10
    • 2017-05-08
    • 1970-01-01
    • 2017-08-16
    • 1970-01-01
    相关资源
    最近更新 更多