我对初学者使用Cake PHP博客教程有问题。尝试打开site.com/posts/index页面时,我收到一条错误消息,指出我需要创建一个PostsController.php文件,但是我已经安装了PostsController.php。
我正在使用蛋糕PHP版本2.3.8
这是我得到的错误
Error: PostsController could not be found.
Error: Create the class PostsController below in file: app\Controller\PostsController.php
我已按照教程讲解,并将文件正确放置在目录中。
这是我创建的PostsController.php文件。
<?
class PostsController extends AppController {
public $helpers = array('Html', 'Form');
public function index() {
$this->set('posts', $this->Post->find('all'));
}
public function view($id = null) {
if (!$id) {
throw new NotFoundException(__('Invalid post'));
}
$post = $this->Post->findById($id);
if (!$post) {
throw new NotFoundException(__('Invalid post'));
}
$this->set('post', $post);
}
}
?>
这是Post.php文件(模型)
<?
class Post extends AppModel {
}
?>
这是index.ctp文件
<!-- File: /app/View/Posts/index.ctp -->
<h1>Blog posts</h1>
<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>
我已经四处搜寻解决方案,发现很多人都遇到相同的问题,但这是他们的解决方案不适用于我的情况,或者是他们自己解决了问题,没有发布解决方案。
请帮我...
更新
该问题已解决,<?php
只是缺少标签。
问题是因为您使用<?
而不是<?php
打开您的php。您可以使用full标记打开php或使用启用短标记php.ini
。
建议不要使用快捷标签“ short cut”,而应使用完整标签组合。随着XML的广泛使用以及其他语言对这些标签的使用,服务器很容易混淆,最终在错误的上下文中解析错误的代码。此外,目标服务器上可能不支持短标签
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句