Create temporary table in CakePHP and load it as a Model

偶尔善良 提交于 2019-12-17 20:26:38

问题


My plan is to create a temporary table using the $this->Model->query(); method then load it as a Model but I'm getting an error staying "Missing Database Table". Turning on debug to level two shows that the temporary table is success fully created but for some reason, when I try and load it as a model it doesn't work. It looks like cake doesn't even try to see if the table exists as there is no "SHOW FULL COLUMNS FROM ...' query being displayed. Not sure how to force cake to check for its existence.

$tmpModel = 'tempModel';
$tmpTable = 'temp_models';

$this->Model->query('CREATE TEMPORARY TABLE `'.$tmpTable ... );
$this->loadModel($tmpModel);

Thanks in advance.


回答1:


$tmpModel = 'TempModel'; // CamelCase

also try, ClassRegisty::init($tmpModel);

final issue may be cache. but dont think so




回答2:


Ok, after looking around a bit I have found a solution that works. The problem was that Cake had already loaded the models caches at page load so used them as reference to the existence of a table. To resolve this problem I used "App::import('Model', $tmpModel);" which created the new modelCache allowing the loadModel script to run successfully.

$tmpModel = 'tempModel';
$tmpTable = 'temp_models';

$this->Model->query('CREATE TEMPORARY TABLE `'.$tmpTable ... );
App::import('Model', $tmpModel);
$this->loadModel($tmpModel);

Thanks anyway




回答3:


After doing google for an hour .. finally found a way to have Model on Temporary table and it works like a charm http://web2.0goodies.com/blog/uncategorized/mysql-temporary-tables-and-cakephp-1-3/



来源:https://stackoverflow.com/questions/5675225/create-temporary-table-in-cakephp-and-load-it-as-a-model

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