2013-12-08 123 views
1

我有一個註冊表單,它一直在工作,直到它沒有。我相信我對代碼做了些什麼,因爲我是laravel 4的新手,所以我無法確定我做錯了什麼。現在我越來越laravel 4重定向問題

此網頁有一個重定向循環。

這是路線文件:

Route::get('/','[email protected]'); 

Route::get('/login', '[email protected]'); 

Route::get('/signup', '[email protected]'); 

/*handled by controller to register the user that signed up*/ 
Route::get('/register', '[email protected]'); 

/* Handle authenticating a user when loggin in*/ 


Route::post('register', array(
    'uses' => '[email protected]', 
    'as' => 'members.register' 
)); 

,這是形式開口:

@section('content') 
{{ Form::open(array('route' => 'members.register')) }}  

...... 

{{ Form::close() }} 
@stop 

並且這是,如果有錯誤,它用於重定向到驗證再次註冊頁面並顯示它們(並且它一直到它打破)

public function register() 
    { 
     $rules = array(
      # place-holder for validation rules 
      'firstname' => 'Required|Min:3|Max:40|Alpha', 
      'lastname' => 'Required|Min:3|Max:40|Alpha', 
      'email'  => 'Required|Between:3,64|Email|Unique:users', 
      'country'  => 'Required', 
      'password' =>'Required|AlphaNum|Between:7,15|Confirmed', 
      'password_confirmation'=>'Required|AlphaNum|Between:7,15' 

     ); 

     /*Create new user if no user with entered email exists. Use validator to ensure all fields are completed*/ 
     $user = new User; 

     $validator = $this->validate(Input::all(), $rules); 
     if ($validator->fails()) 
     { 

      return Redirect::to('register')->withErrors($validator); 

     }else{ 
      echo "Success"; 
     } 

    } 

感謝您的幫助:)

回答

3

更改以下行

return Redirect::to('register')->withErrors($validator); 

return Redirect::back()->withInput()->withErrors($validator); 

您所呼叫的路徑登記無限次。

刪除此路線以及。你只需要後路線。

/*handled by controller to register the user that signed up*/ 
Route::get('/register', '[email protected]'); 
+0

感謝Anam的幫助。將嘗試一下 – spacemonkey