duanlu8613 2013-07-27 15:58
浏览 19
已采纳

Cakephp博客教程错误PostsController缺失

I am having a problem with Cake PHP blog tutorial for beginners. I got an error stating I need to create a PostsController.php file, when trying to open the site.com/posts/index page, but I already have the PostsController.php in place.

I am using cake PHP ver 2.3.8

This is the error I get

Error: PostsController could not be found.

Error: Create the class PostsController below in file: app\Controller\PostsController.php

I've followed the tutorial to the letter, and put the files correctly in the directory.

Here is the PostsController.php file I created.

<?
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);
    }
}
?>

Here is the Post.php file (the model)

<?
class Post extends AppModel {
}
?>

and here is the index.ctp file

<!-- 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>

I've already googled around for the solution and found out that a lot of people is having the same problem, but It's either their solution is not working for my case or they fixed it by themself and didn't post the solution.

Please help me...

UPDATE

the issue has been resolved, it was the <?php tag that was missing.

  • 写回答

2条回答 默认 最新

  • dqajyxqem115006813 2013-07-27 16:16
    关注

    The problem is because you are using <? instead of <?php to open your php. You can either use full tag to open php or enable short tags using php.ini.

    It's been recommended not to use the short tag "short cut" and instead to use the full tag combination. With the wide spread use of XML and use of these tags by other languages, the server can become easily confused and end up parsing the wrong code in the wrong context. Also short tags may not be supported on the target server

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab