2014-12-03 38 views
0

在route.php我有以下...如何設置URL,這樣它加載用戶頁面

Route::get('/user/{username}', array(
    'as' => 'profile-user', 
    'uses' => '[email protected]' 
)); 

在ProfileController可我有以下...

class ProfileController extends BaseController { 
    public function user($username) { 
     $user = User::where('username', '=', $username); 

     if($user->count()) { // if the corresponding user exists... 
      $user = $user->first(); 

      return View::make('profile.user') 
        ->with('user', $user); 
     } 

     return App::abort(404); 
    } 
} 

在導航。 blade.php我有以下...

<li><a href="{{ URL::route('profile-user') }}">User Profile</a></li> 

我怎樣才能讓這個navigation.blade.php將提供正確的鏈接到用戶配置文件?目前,該鏈接看起來像HTML以下...

http://website.dev/user/%7Busername%7D 

我想它看起來就像這樣:

http://website.dev/user/currentlyLoggedInUserName 

回答

0

這就是我解決它的方法。我會把答案留給其他人。

<li><a href="{{ URL::route('profile-user', Auth::user()->username) }}">User Profile</a></li> 
0

您可以嘗試使用HTML::link。例如:

{{ HTML::link('/user/<?=$user_name?>', 'User Profile')}} 
0

您應該使用

<li><a href="@{{ URL::route('profile-user') }}">User Profile</a></li> 

,因爲它是一個Laravel PHP函數URL(),必須首先解決,並將結果傳遞給把手。

相關問題