2014-02-07 148 views
0

我有路由资源,并且正常工作,我想将其更改为Route::controllerLaravel使用控制器路由

但经过定义,我在php artisan route得到错误:

+--------+------------------------------------+-----------+---------------------------------+----------------+---------------+ 
    | Domain | URI        | Name  | Action       | Before Filters | After Filters | 
    +--------+------------------------------------+-----------+---------------------------------+----------------+---------------+ 
    |  | GET index       | index  | Closure       |    |    | 
    |  | GET admin/index     | dashboard | Closure       |    |    | 
    |  | GET logout       | logout | Closure       |    |    | 
    |  | POST auth       | auth  | Closure       | csrf   |    | 
    |  | GET login       | login  | Closure       |    |    | 
    |  | GET admin/admin/profile/{_missing} |   | [email protected] |    |    | 
    +--------+------------------------------------+-----------+---------------------------------+----------------+---------------+ 

我目前的路线是:

Route::resource('profile' , 'ProfileController', array('as'=>'profile')); 

,我想改变这种状况到:

Route::controller('admin/profile', 'ProfileController', array('index'=>'profile.index')); 

如何解决这个问题?

回答

0

用途:

Route::resource('profile, 'ProfileController', array('as' => 'profile', 'names' => array('index' => 'profile.index'))); 

而不是上述任何一种途径。

+0

你看过我的quastion吗? –

+1

我的确看过你的问题,并且我同意他们在[this]中给出了答案的人(http://stackoverflow.com/questions/19102534/laravel-4-routeresource-vs-routecontroller-which-touse)帖子。使用:: controller是不好的做法,应该避免。出于这个原因,我推荐了上面这行代码来完成你的要求。 – Patrick

+0

和你的报价是'资源':) –

2

这不是错误,资源和控制器路由是完全不同的东西。

资源路由具有预定义的路由列表(索引,创建,存储,删除,更新)。如果你没有在你的控制器中设置的方法,它仍然可以工作,除非有人击中了这条路线。

控制器路由依赖于您的控制器方法:

public function getIndex() {} 
public function getCreate() {} 
public function postStore() {} 

方法名预定义为

<http method><your action name>() 

如果这些方法都没有出现在你的控制器,Laravel不会让他们在你的路由列表。

所以,只需要创建一个

public function getIndex() {} 

在你的控制器和运行

php artisan route 

再次。

+0

谢谢。我现在得到这个结果.'GET admin/admin/profile/index/{one?}/{two?}/{three?}/{four?}/{five?}'如何设置'as'我的链接是'/ admin/profile'如何解决这个问题? –

+0

这些路由在'route :: group'里面吗? –

+0

我有一条路线进入'group' –