我正在尝试为内容模型控制器创建一个索引方法,我收到以下错误,我在这里搜索但没有找到相关的答案。请查看以下代码和屏幕截图:
Content.php:
class Content extends AppModel{
public $name = 'Content';
}
ContentsController.php:
class ContentsController extends AppController {
public $name = 'Contents';
public function index() {
$this->set('Contents', $this->Content->find('all'));
}
}
index.ctp:
<h1>View All Content</h1>
<table>
<tr>
<th>ID</th>
<th>Title</th>
<th>Content</th>
</tr>
<?php foreach ($Contents as $content) : ?>
<tr>
<td><?php echo $this->$content['Content']['id']; ?></td>
<td><?php echo $this->$content['Content']['title']; ?></td>
<td><?php echo $this->$content['Content']['content']; ?></td>
</tr>
<?php endforeach; ?>
</table>
截图: http://postimg.org/image/sslcgoutx/
请帮助我,因为我是cakephp的新手并且正在学习它。
答案 0 :(得分:1)
在index.ctp
中试试<h1>View All Content</h1> <table>
<tr>
<th>ID</th>
<th>Title</th>
<th>Content</th>
</tr>
<?php foreach ($Contents as $content) : ?>
<tr>
<td><?php echo $content['Content']['id']; ?></td>
<td><?php echo $content['Content']['title']; ?></td>
<td><?php echo $content['Content']['content']; ?></td>
</tr>
<?php endforeach; ?>
</table>