Paginate TEMPORARY TABLE in Cakephp?

安稳与你 提交于 2020-01-03 03:03:15

问题


Let say I have a table named 'products' and Model named 'Product'.

'products' table has 3 fields id,title,price,created

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.

using $this->paginate();

eg.

table_products

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

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

*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*


回答1:


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.

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');

Good Luck



来源:https://stackoverflow.com/questions/4732907/paginate-temporary-table-in-cakephp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!