2015-01-07 3 views
0

laravel을 사용하여 작은 프로젝트를 수행하고 있지만 라우팅이 작동하지 않습니다. 아래에서 올바른 방향으로 가리 키십시오. 아래 코드를 게시하십시오.Larevel 4.2 라우팅 매개 변수 % 7Busername % 7D가 작동하지 않습니다.

라우터

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

컨트롤러

public function index($username = null) { 
     $username = Sentry::getUser()->username; 

     return View::make('home.profile') 
       ->with('title', 'From controller') 
->with('username', $username); 

    } 

난 아직도 내가 당신이 원하는 생각하지만 로그인 컨트롤러에 profile에 리디렉션을 볼 수 없습니다http://social.app/%7Busername%7D

public function postLogin(){ 
     $credentials = Validator::make([ 
        'email' => Input::get('email'), 
        'password' => Input::get('password') 
         ], [ 
        'email' => 'required|email', 
        'password' => 'required|alpha_num|between:8,15', 
     ]); 
     if ($credentials->fails()) { 
      return Redirect::route('login') 
          ->withInput() 
          ->with('title', 'Welcome to mySite | login') 
          ->withErrors($credentials->getMessageBag()); 
     } else { 
      try { 
       $credentials = array(
        'email' => Input::has('email') ? Input::get('email') : null, 
        'password' => Input::has('password') ? Input::get('password') : null, 
       ); 

       // Log the user in 
       $user = Sentry::authenticate($credentials, Input::has('remember_me') and Input::get('remember_me') == 'checked'); 

       return View::make('home.profile'); 
      } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { 
       return View::make('users.login') 
           ->with('title', 'wrong login') 
           ->with('message', 'Email filed is required'); 
      } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { 
       return View::make('users.login') 
           ->with('title', 'something went wrong') 
           ->with('message', 'Password filed is required'); 
      } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { 
       return View::make('users.login') 
           ->with('title', 'wrong Password') 
           ->with('message', 'The password/login is incorrect.'); 
      } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { 
       return View::make('users.login') 
           ->with('title', 'Not found') 
           ->with('message', 'Sorry we can't found the user.'); 
      } 

     } 
    } 
+1

문제는 아마 URL을 생성 할 때입니다. 코드를 보여줄 수 있습니까? – lukasgeiter

+0

로그인에 성공하면 프로필로 사용자를 보냅니다. 그러나 URL은 작동하지 않습니다. 여기에 내 로그인 컨트롤러가 있습니다. –

답변

0

URL 이런 식으로 :

// ... 

$user = Sentry::authenticate($credentials, Input::has('remember_me') and Input::get('remember_me') == 'checked'); 
return Redirect::route('profile', $user->username); 

// ... 

(!) 참고 : 루트 수준의 URL과 사용자 이름은 사용자를 만들 때 확인해야한다는 것을 의미하므로 사용자 이름이 기존의 URL 중 하나와 충돌하지 않도록주의.

+0

안녕하세요 Lukasgeiter, 도와 주셔서 감사합니다. 아직 질문이 하나 더 있습니다. 어떻게 하시겠습니까? URL에서 을 삭제할 수 있습니까? http://social.app/profile?myUserName –

+0

'Redirect :: route' 및 'Redirect :: to'가 아닌가요? – lukasgeiter

+0

예, 확실하게 사용했습니다 return Redirect :: route ('profile', $ user-> username); –