【问题标题】:Paginate TEMPORARY TABLE in Cakephp?在 Cakephp 中为临时表分页?
【发布时间】:2011-06-11 14:23:54
【问题描述】:

假设我有一个名为“products”的表和一个名为“Product”的模型。

'products' 表有 3 个字段 id,title,price,created

我想计算 cal_price(每条记录和搜索日期不同)并创建一个临时表,其中包含 4 个字段,即 id、title、price、cal_price,按 cal_price 排序

现在,我只想为这个临时表分页。

使用 $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 排序“temp_table”订单并分页

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') 来解决问题*

【问题讨论】:

    标签: php cakephp model pagination temp-tables


    【解决方案1】:

    如果您尊重表名称的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');
    

    祝你好运

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多