2013-06-18 58 views
0

我想在Laravel中做一個分頁,但是我不斷收到錯誤。在PHP中尋呼Laravel

我嘗試把

->paginate(3) 

在迴歸,但我不斷收到類似呼叫錯誤未定義的方法Laravel \分頁程序:: get()和調用未定義的方法Laravel \分頁程序:: ORDER_BY()

public function get_index() 
{ 
    $categories = Category::all(); 
    return View::make("stories.index") 
     ->with("title","Sexnoveller") 
     ->with("categories", $categories) 
     ->with("stories", DB::table('stories') 
     ->order_by('id', 'desc')->get()); 
} 

回答

1

要使用分頁調用paginate(),而不是get()。在你的情況下,將是:

return View::make("stories.index") 
     // ... 
     ->with("stories", DB::table('stories') 
     ->order_by('id', 'desc')->paginate(3)); 

然後在視圖中,只記得遍歷$stories->results

1

我建議爲故事表創建一個模型。完成後,您可以執行如下操作:

Story::orderby('story_name', 'ASC')->paginate(10);