CakePHP:创建临时表并使用它 [英] CakePHP: create temporary table and use it

查看:63
本文介绍了CakePHP:创建临时表并使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在CakePHP 2.x中创建一个临时表,但是我总是收到消息错误:在非对象上调用成员函数query()。

I'm trying to create a temporary table within CakePHP 2.x, but I always receive the message "Error: Call to a member function query() on a non-object".

我做了一些研究并找到了解决方案,但该解决方案不适用于我:

I did some research and found a solution, but this one is not working for me: Create temporary table in CakePHP and load it as a Model

编辑:
现在,以下代码产生另一个错误:错误:在数据源默认值中未找到模型DevicesCl的表devices_cls。

The following code now produces a different error: "Error: Table devices_cls for model DevicesCl was not found in datasource default."

此处是我的代码:

class DevicesController extends AppController {

public $uses = array('Device','Client');

public function index(){
    $conditions = array();

    $tmpModel = 'DevicesCl';
    $tmpTable = 'devices_cls';

    $this->loadModel('DevicesCl');
    $this->DevicesCl->query("CREATE TEMPORARY TABLE IF NOT EXISTS devices_cls AS (SELECT uuid,ownerUuid,status,os,imei,updatedOn,msisdn,model FROM device)" );

由于我对CakePHP很陌生,是否需要添加其他模型类?我不这么认为,因为这应该由临时表处理-对吗?

As I'm quite new to CakePHP, do I need to add an additional model class? I don't think so, as this should be handled by the temporary table - right?

感谢您的支持!

推荐答案

class DevicesController extends AppController {

public $uses = array('Device','Client');

public function index(){
    $conditions = array();

    $tmpModel = 'DevicesCl';
    $tmpTable = 'devices_cls';

    $this->loadModel('DevicesCl');
    $this->DevicesCl->useTable=false;
    $this->DevicesCl->query("CREATE TEMPORARY TABLE IF NOT EXISTS devices_cls AS (SELECT uuid,ownerUuid,status,os,imei,updatedOn,msisdn,model FROM device)" );
    $this->DevicesCl->useTable = $tmpTable;

这篇关于CakePHP:创建临时表并使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆