2013-10-15 45 views
0

我是新來的Laravel,我使用Laravel 4,我試圖創建一個用戶控制器,如下所示:調用未定義的方法 - Laravel

class UserController extends BaseController { 

    public function getIndex(){ 
    } 

    public function showProfile($id){ 

     echo "$id"; 

     View::make('user.profile'); 
    } 


    public function getNew(){ 
    } 

    public function postNew(){ 

    } 

    public function getLogin(){ 
    } 

在路線我想用: Route :: controller('user','UserController');

它的工作正常所有期望(showProfile),例如,當我去../user/profile/2 我得到調用未定義的方法。

注意: 我可以使用

Route::get('user', '[email protected]'); 
Route::get('user/new', '[email protected]'); 
Route::post('user/new', '[email protected]'); 
Route::get('user/login', '[email protected]'); 
Route::get('user/{id}', '[email protected]'); 

,它會正常工作,但我不認爲這是一個很好的做法

回答

1

沒有您爲

../user/profile/2 
定義路線

你試過類似的東西:

Route::get('user/profile/{id}', '[email protected]'); 
+1

是的我試過了,但它覆蓋了所有其他方法,如用戶/登錄 ,但我添加了一些使它工作的東西 Route :: get('user/{id}','UserController @ showProfile') - > where 'id','[0-9] +'); 所以它不覆蓋其他方法 – Elmasry

+0

但這仍然不理想,如果我想通過{用戶名}而不是{id},那麼我不能使用where('id','[0-9 ] +'); – Elmasry

+0

'user/profile/{id}'如何覆蓋其他路線?其他路線不包含他們的「個人資料」 –

相關問題