0

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

我怎么能那样做?

4

1 回答 1

0

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

于 2013-11-10T17:47:56.830 回答