dongzhi6463 2013-09-04 16:11
浏览 29
已采纳

Cakephp模型有几个数据源

I have a model called Forwards this model uses a table from my Database. However it is required for some of the views connected to this model to use my costum datasource (This is a datasource i have created which links it to an API).

Now my question how can i add a datasource to a Model that already has a datasource.

And how can i tell the Paginator that it has to use this datasource when it is paginating (so it doesnt confilct)

Update

I have been reading abit it seems the only way to use two datasource in a model is to Hack abit, so i was wondering is it possible to use two models from one controller while still paginating?

i want to keep these settings

public $paginate = array(
    'fields' => array(
        'Offer.id',
        'Offer.name',
        'OfferUrl.preview_url',
        'Stat.ltr',
        'Stat.cpc',
        'Category.name',
        'Country.name')

, 'conditions' => array('Stat.date' => array(
            'conditional' => 'BETWEEN'
        , 'values' => array()
        ),
    ),
    'group' => array('Stat.offer_id'),
    'Method' => 'getStats',
    'totals' => true,
    'limit' => 20
);

I set these within my controller

  • 写回答

1条回答 默认 最新

  • dousha1831 2013-09-04 16:27
    关注

    You can change the data source by calling Model::setDatasSource().

    You can change the model the paginator uses by:

    $this->Paginator->paginate($ModelInstance);
    

    Or

    $this->Paginator->paginate('ModelName');
    

    You might want to read that page.

    Don't use Controller::paginate any more but instead $this->Paginator->settings. For settings per model use

    $this->Paginator->settings['ModelName'] = array(/*...*/);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 qgcomp混合物线性模型分析的代码出现错误:Model aliasing occurred
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'