Cakephp 在 default.ctp 处显示数据 mysql



我需要在从内容调用的页面(View/Layouts/default.ctp)中显示MySQL中的一些项目.php(View/Pages/Items.ctp)

我该怎么做?

这取决于您使用的表的名称。
您可以在控制器中使用简单代码。( 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 检索您的数据

最新更新