CakePHP重定向404s

CakePHP重定向404s,php,cakephp,mod-rewrite,http-status-code-404,Php,Cakephp,Mod Rewrite,Http Status Code 404,我第一次尝试学习CakePHP(我通常只学习纯代码PHP),我从他们主持的“官方”博客教程开始: 到目前为止,我已经设置了一个虚拟主机(在OSX10.8.2上),并使用CakePHP的默认索引页来确保它从数据库中正确读取,app/tmp文件夹对于Apache是递归可写的,等等 在设置了初始博文视图之后,当我尝试关注博文时遇到了问题,它说您现在可以在(将“www.example.com”调整为我的本地服务器名)“cakeblog/Posts/index”上查看博文。我很确定我有一些修改的问题,但

我第一次尝试学习CakePHP(我通常只学习纯代码PHP),我从他们主持的“官方”博客教程开始:

到目前为止,我已经设置了一个虚拟主机(在OSX10.8.2上),并使用CakePHP的默认索引页来确保它从数据库中正确读取,app/tmp文件夹对于Apache是递归可写的,等等

在设置了初始博文视图之后,当我尝试关注博文时遇到了问题,它说您现在可以在(将“www.example.com”调整为我的本地服务器名)“cakeblog/Posts/index”上查看博文。我很确定我有一些修改的问题,但我不知道是什么。 无论何时发生这种情况,我的Apache错误日志如下:

[Thu Feb 14 09:18:10 2013] [error] [client 127.0.0.1] File does not exist: /Users/bailey/Sites/cakeblog/posts

[Thu Feb 14 09:18:10 2013] [error] [client 127.0.0.1] File does not exist: /Users/bailey/Sites/cakeblog/favicon.ico
我知道favicon存在于我的webroot文件夹中,位于/Users/bailey/Sites/cascade/extranet-cake/app/webroot。 如果我理解路由权,那么cakeblog/posts/index应该是PostsController的控制器,/index应该是PostsController“index()”中的操作/方法。所以它似乎不认识控制器

我在博客教程之后设置的代码是:

(app/Model/Post.php):


(app/Controller/PostsController.php):


(app/View/Posts/index.ctp):


博客帖子
身份证件
标题
创建日期
这是我第一次真正了解CakePHP,我在其他任何帖子中都找不到解决方案,除了怀疑mod_重写问题的间接原因。 有人知道我遗漏了什么吗?我也可以根据要求发布我的httpd.conf文件。

[p>[SOLVED]

愚蠢的错误——原来我使用了app/webroot以外的子文件夹作为webroot。一旦我改变了这个,它工作得很好

如果我想使用不同于默认值的webroot,JeremyHarris在上面的评论中给出了另一种选择,并且在CakePHP文档中得到了支持:


谢谢大家的帮助

不要使用app/View/Posts/index.ctp,尝试使用app/views/Posts/index.ctp而不要使用app/Controller/PostsController.php,尝试使用app/controllers/Posts\u Controller.php而不要使用app/Model/Post.php,尝试使用app/models/Post.php不确定这是否是您的问题,但CakePHP在大多数默认设置中是区分大小写的。好主意,但没有骰子。:/所有的重命名都没有任何效果,但我一定要记住蛋糕是区分大小写的。我不知道。如果cake正在您域的子文件夹中运行,如www.example.com/cakeblog,则需要将
RewriteBase cakeblog/
添加到webroot下的.htaccess文件。关于文件重命名,如果您使用的是cake 2.0或更新版本,则文件夹结构类似于app/View/Posts/index.ctp。在1.3及更早版本中,它类似于app/view/posts/index.ctp。您确定您的网站文件夹包含重写URL所需的
.htaccess
文件吗?
<?php

    /*
        Model: represents a data model (object).
            Examples -> a blog, a post, a comment on a post
    */
    class Post extends AppModel
    {

    }

?>
<?php
    /*
        Plays with Posts Model and gets work done.

        - function "foo()" means that the function is accessed by
            going to DOMAIN/posts/foo
    */
    class PostsController extends AppController
    {
        public $helpers = array('Html', 'Form');

        // An action!
            // www.example.com/posts/index => listing of all posts
        /*
            Sets the view variable called ‘posts’ equal to the return 
            value of the find('all') method of the Post model.
        */
        public function index()
        {
            $this->set('posts', $this->Post->find('all'));
        }
    }

?>
<!-- /app/View/Posts/index.ctp -->

    <h2> Blog Posts </h2>
    <table>
        <tr>
            <th> ID </th>
            <th> Title </th>
            <th> Date Created </th>
        </tr>
        <!-- Output the actual posts -->
        <?php
            foreach ($posts as $post)
            {
                /* Data ~ $post[ModelName][VariableName] */
                $id = $post['Post']['id'];
                /*
                    "$this->Html" ~ a Helper
                        link() generates an HTML link with given title and URL
                */
                $titleLink = 
                    $this->Html->link($post['Post']['title'],
                                        array('controller' => 'posts', 'action' => 'view', $post['Post']['id']));

                $dateCreated = $post['Post']['created'];


                $out = "<tr>
                            <td>$id</td>
                            <td>
                                $titleLink
                            </td>
                            <td>$dateCreated</td>
                        </tr>";

                echo $out;
            }

            unset($post);
        ?>
    </table>