在跟着CakePHP写Blog这个小代码时,访问这个action:‘http://localhost/cakephp/posts/index’,Chrome报错了,错误如下:
Fatal Error
Error: syntax error, unexpected 'endforeach' (T_ENDFOREACH)
File: D:\Program Files\wamp\www\cakephp\app\View\Posts\index.ctp
Line: 48
php code:
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Created</th>
</tr>
<!-- Here is where we loop through our $posts array, printing out post info -->
<?php foreach ($posts as $post); ?>
<tr>
<td><?php echo $post['Post']['id']; ?></td>
<td>
<?php echo $this->Html->link($post['Post']['title'], array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); ?>
</td>
<td><?php echo $post['Post']['created']; ?></td>
</tr>
<?php endforeach; ?>
<?php unset($post); ?>
</table>
网上参考链接:
http://stackoverflow.com/questions/20919202/php-syntax-error-unexpected-endforeach-t-endforeach