Error: syntax error, unexpected 'endforeach' (T_ENDFOREACH)

来源:互联网 发布:医院没有编制 知乎 编辑:程序博客网 时间:2024/05/08 02:00

在跟着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>

稍稍在网上搜了一下,没细看,后面再仔细对着看时,发现foreach结束时应该是“:” (冒号), 而不是分号(";"), 我没注意写错了。

网上参考链接:

http://stackoverflow.com/questions/20919202/php-syntax-error-unexpected-endforeach-t-endforeach

0 0
原创粉丝点击