我是 cakePhp 开发的新手。我一直坚持以下问题:
我制作了一些模型、 Controller 和 View ——效果很好。问题是,在生产之后,我必须在逻辑上“连接”到其他表的数据库中创建新表(Transactionaltemp 表和相应的模型和 Controller ),但技术上不需要 - for前任。它保存有关 user_id、时间、IP 等的临时信息。因此,其他表不需要直接连接到该表。
问题是当我尝试时(在transactionaltemps_controller
之外的其他 Controller 中):
$this->loadModel('Transactionaltemp');
我收到错误 - 未找到模型(这是真的,因为缓存中缺少模型)。足够有趣的 transactionaltempls_controller
位于缓存中(在 cake_controllers_list
文件中)。
我尝试了以下方法来解决该问题:
- 清除缓存
- 禁用缓存
- 尝试在我想要使用的 Controller 中使用
uses={..}
代码mymodels_controller
- 尝试使用
init('Transactionaltemp')
没有成功。这是相应的代码: 型号:
<?php
class Transactionaltemp extends AppModel
{
var $name = 'Transactionaltemp';
function beforeSave() {
return true;
}
}
?>
Controller :
<?php
class TransactionaltempsController extends AppController
{
var $name = 'Transactionaltemps';
var $scaffold;
}
?>
我将非常感谢任何帮助!!!
最佳答案
App:Import('Model','Transactionaltemp');
$this->Transactionaltemp= new Transactionaltemp;
我希望这可能有效
关于CakePHP 不加载模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4984749/