2011-01-19 102 views
1

假設我有一張名爲'產品'的表格和名爲'產品'的型號。CakePHP的Paginate臨時表?

「產品」表有3個字段ID,名稱,價格,創造

我想計算cal_price(其中每個記錄和搜索的一天中不斷變化),並創建一個臨時表與4個字段,即ID,標題,價格,cal_price與cal_price訂單

現在,我只想要分頁這個臨時表。

using $ this-> paginate();

例如。

table_products 

id title price created 
3  demo1 23  2011-12-12 
4  demo2 43  2011-12-13 
56  demo3 26  2011-12-16 

排序「temp_table」由cal_price秩序和分頁

temp_table 

id title price cal_price created 
3  demo1 23  12  2011-12-12 
4  demo2 43  43  2011-12-13 
56  demo3 26  88  2011-12-16 

*潛在的問題的解決方案是怎麼做的我分配temp_table到一個模型在運行時,因爲一旦我這樣做,我可以使用$ this-> paginate('temp_model')並解決問題*

回答

0

如果您已經考慮到表名的conventions,那麼您不需要臨時表的模型,因此「temp_table」將不起作用,導致名稱必須是複數。

假設您的臨時表被稱爲「temp_prices」(我沒有使用表上的前綴) ,模型的名稱應該是「TempPrice」。爲了分頁表使用該控制器

$this->loadModel('TempPrice'); //will load the model on the controller 
$this->paginate['TempPrice'] = array(); //you can change the pagination options here 
$resp = $this->paginate('TempPrices'); 

好運

+0

在將這項工作在這種情況? http://stackoverflow.com/questions/5675225/create-temporary-table-in-cakephp-and-load-it-as-a-model,因爲我似乎得到一個「表未找到」錯誤? – bpneal 2011-04-15 10:19:57