问题描述
假设我有一个名为products的表和名为Product的模型。
Let say I have a table named 'products' and Model named 'Product'.
'products'表有3个字段id,title,price,created
'products' table has 3 fields id,title,price,created
我想计算cal_price(每个记录和搜索日期不同),并创建一个包含4个字段的临时表,即id,title,price,cal_price,order by cal_price
I want to calculate cal_price (which varies per record and day of search) and create a temporary table with 4 fields i.e. id,title,price,cal_price with order by cal_price
现在,我只需要分页这个临时表。
Now, all I want is to paginate this temporary table.
使用$ this-> paginate
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
通过cal_price和paginate对'temp_table'排序
sort 'temp_table' order by cal_price and paginate
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')并解决问题*
*The underlying problem to the solution is HOW DO I assign temp_table to a model at run time because once I do it I can use $this->paginate('temp_model') and solve the problem*
推荐答案
如果您尊重了的表名,所以temp_table不工作,因为名称必须是复数。
you dont need a model for your temporary table if you have respected the conventions for the tables' names, so "temp_table" wont work, cause the name must be plural.
被称为temp_prices(我不使用表上的前缀)
,模型的名称应该是TempPrice。要对页面进行分页,请在控制器上使用此标签。
Let's say that your temporary table is called "temp_prices" (i'm not using prefixes on tables),the name of the Model should be "TempPrice". To paginate the table use this on your controller
$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');
祝你好运
这篇关于Paginate TEMPORARY TABLE在Cakephp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!