开发者

Create temporary table in CakePHP and load it as a Model

My plan is to create a temporary table using the $this->Model->query(); method then load it as a开发者_StackOverflow中文版 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.


$tmpModel = 'TempModel'; // CamelCase

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

final issue may be cache. but dont think so


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


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜