我需要在从 Content.php (View/Pages/Items.ctp) 调用的页面 (View/Layouts/default.ctp) 中显示 MySQL 中的一些项目
我怎么能那样做?
这取决于您使用的表的名称。
您可以使用控制器中的简单代码。( PagesController.php
)
$this->set('data', $this->Model->find('all'));
// change Model for the name of your model.
如果模型没有被 Cakephp 自动加载。
您需要在上述相同控制器的功能中进行设置。
$this->loadModel('Model'); // change Model for the name of your model.
在视图 ( Items.ctp
) 中:
foreach($data as $d){
echo $d['Model']['name'];
// change Model for the name of your model.
}
另请阅读Cakephp 检索您的数据