2013-06-04 65 views
1

現在我正在學習和測試Laravel 4,並且我對腳本有一點關注。Laravel 4重定向頭

我想插入信息到數據庫,然後重定向到索引頁;問題是當我刷新頁面時,它顯示要重新發送的消息。

這裏是我使用的代碼:

public function store() 
{ 
    $new_cat = new Cat; 
    $new_cat->name = Input::get('new_cat'); 
    $new_cat->age = Input::get('age_cat'); 

    $new_cat->save(); 
    return Redirect::action('[email protected]'); 

} 
+1

你可以張貼一些代碼,以便有針對行上下文?另外,你可以發佈錯誤消息嗎? – fvrghl

+0

沒有錯誤,我重定向到索引頁並刷新它,瀏覽器顯示重新發送數據的彈出窗口。 () 我只是希望瀏覽器不顯示這個彈出框 –

+0

'公共功能商店() {0} {new_cat = new Cat; $ new_cat-> name = Input :: get('new_cat'); $ new_cat-> age = Input :: get('age_cat'); $ new_cat-> save(); return Redirect :: action('CatsController @ index'); }' –

回答

0

也許這將工作

return Redirect::to('route_name')->withInput(); 
+0

不,這是行不通的!謝謝 –

+0

它可能與頭部鏈接,如在PHP中,你可以這樣做: 'header('Location:index.php'); 退出();' –

+0

這不是在存儲功能工作,但在路線是......路線::資源或什麼問題? –

2

正確的方式來處理POST請求了重定向是發出303個狀態碼。

http://en.wikipedia.org/wiki/HTTP_303

使用你原來的代碼:

return Redirect::action('[email protected]', array(), 303); 

或者越智的:

return Redirect::to('route_name', 303)->withInput(); 
+0

感謝您的回答,我會嘗試 –