CakePHP:创建临时表并使用它 [英] CakePHP: create temporary table and use it
问题描述
我试图在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屋!