【问题标题】:Laravel wildcard for controller routes?用于控制器路由的 Laravel 通配符?
【发布时间】:2014-02-11 15:58:40
【问题描述】:

我定义了一个Route 用于对控制器路由进行分组,并在使用此URL 之后:

http://localhost/alachiq/public/admin/profile

它可以显示个人资料视图。但如果用户输入:

http://localhost/alachiq/public/admin/profile/

重定向到http://localhost/admin/profile,我收到此错误:

Not Found

The requested URL /admin/profile was not found on this server.
Apache/2.4.6 (Debian) Server at localhost Port 80

如何在控制器中使用通配符?

我的路线:

Route::group(array('prefix'=> 'admin' ,'before'=>'auth'), function(){
    Route::controller('profile', 'ProfileController',array('getIndex'=>'profile.index', 'postUpdate'=>'profile.update'));

});

【问题讨论】:

    标签: php laravel laravel-4


    【解决方案1】:

    我猜你的 DocumentRoot 应该是 /path/to/alachiq/public,但如果你想让它保持原样,你必须修改 htaccess 以将子文件夹考虑在内。
    它看起来像这样RewriteRule ^(.*)/$ /alachiq/public/$1 [L,R=301]

    【讨论】:

      【解决方案2】:

      如果我明白,您正在寻找这个:

      class UserController extends BaseController {
      
          function __construct() {
              $this->beforeFilter('auth', array('except' => array('store', 'update')));
              $this->beforeFilter('csrf', array('on' => 'post'));
          }
      }
      

      您可以找到更多代码:Laravel 4 except filter in controller constructor

      【讨论】:

        猜你喜欢
        • 2013-01-30
        • 2013-05-19
        • 2013-05-21
        • 1970-01-01
        • 2015-11-16
        • 2013-12-19
        • 2017-07-17
        • 1970-01-01
        • 2015-02-22
        相关资源
        最近更新 更多