命名的宁静路线在Laravel 4 [英] Named restful routes in Laravel 4

查看:101
本文介绍了命名的宁静路线在Laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我已经能够使宁静的控制器正常工作

So, I've been able to get restful controllers working with

Route::controller('users','UserController');

class UserController extends BaseController {
    public function getAccount(){}
}

,因此/users/account起作用.但是,如果我尝试做类似的事情

and so /users/account works. However if I try to do something like

Route::any('account',array('as' => 'account','uses' => 'UserController@account'));

并转到/account,它不起作用(NotFoundHTTPException).有没有一种方法可以结合使用命名路由和静态控制器?我喜欢宁静的系统如何分解请求,以及命名路由如何封装URI并将其与函数名分离.这在Laravel 3中有效.我是否在语法中缺少某些内容,还是Laravel 4故意禁止了这种混合搭配行为?谢谢...

and go to /account, it doesn't work (NotFoundHTTPException). Is there a way to use named routes and restful controllers in conjunction? I like how the restful system breaks up requests, and how named routes encapsulate the URI's and decouple them from the function names. This worked in Laravel 3. Am I missing something in the syntax, or did Laravel 4 purposefully disallow this kind of mix-and-match behavior? Thanks...

推荐答案

尝试一下:

Route::get('/',array('as'=>'named_route','uses'=>'yourRestfulController@getMethod'));

这对我很好.诀窍是在@部分之后添加操作类型.与L3不同,您应该使用该方法的全名.

This works nice for me. The trick was adding the action type after @ part. You should use the full name of the method unlike in L3.

这篇关于命名的宁静路线在Laravel 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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