在 CakePHP 中创建临时表并将其作为模型加载
我的计划是使用 $this->Model->query(); 创建一个临时表方法然后将其加载为模型,但我收到错误“缺少数据库表”。将调试打开到第二级表明临时表已成功完全创建,但由于某种原因,当我尝试将其作为模型加载时,它不起作用。看起来 cake 甚至没有尝试查看该表是否存在,因为没有显示“SHOW FULL COLUMNS FROM ...”查询。不知道如何强制 cake 检查其存在。
$tmpModel = 'tempModel';
$tmpTable = 'temp_models';
$this->Model->query('CREATE TEMPORARY TABLE `'.$tmpTable ... );
$this->loadModel($tmpModel);
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
$tmpModel = 'TempModel'; // CamelCase
也尝试一下,
ClassRegisty::init($tmpModel);
最终问题可能是缓存。但不这么认为
$tmpModel = 'TempModel'; // CamelCase
also try,
ClassRegisty::init($tmpModel);
final issue may be cache. but dont think so
好吧,环顾四周后,我找到了一个可行的解决方案。
问题是 Cake 已经在页面加载时加载了模型缓存,因此将它们用作表是否存在的引用。为了解决这个问题,我使用了“App::import('Model', $tmpModel);”它创建了新的 modelCache,允许 loadModel 脚本成功运行。
无论如何,谢谢
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.
Thanks anyway
经过一个小时的谷歌搜索后..终于找到了一种将模型放在临时表上的方法,它的工作原理就像一个魅力
http://web2.0goodies.com/博客/未分类/mysql-temporary-tables-and-cakephp-1-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/