假设我有一个 mysql 数据库,并且有 3 个实体,
- 电视
- 笔记本电脑
- 配件
每个实体都包含特定信息。
我想将这些数据打印到单个 CTP 页中。
我该怎么做?
我不想使用 foreign_key
。
最佳答案
您可以使用 Cake 的 loadModel 函数将任何表中的数据调用到当前 Controller 中。更多信息见底部page .
$this->loadModel('YourModel');
然后设置变量以使其在您的 View 中可用:
$this->set('yourModel', $this->YourModel->find('all', $settings);
$this->loadModel('YourOtherModel');
$this->set('yourOtherModel', $this->YourOtherModel->findI('all', $settings);
现在已经从模型中设置了两个变量,它们可以在您的 View 中使用。
(使用 debug 查看所有可用的数据,即 debug($yourModel);
您可以将其放入 Controller 操作中,它将输出在页面顶部或中的任何位置您的 View 文件)
关于php - 如何在cakephp的一页中显示不同数据库表实体的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25662259/