繁体   English   中英

CakePHP重定向404

[英]CakePHP Redirect 404s

我正在尝试第一次学习CakePHP(我通常只是直接编写PHP代码),而我从他们主持的“官方”博客教程开始: http//book.cakephp.org/1.3/en/The -手册/教程-示例/Blog.html

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

设置初始“帖子视图”后立即尝试关注博客时,我遇到了问题,它说您现在可以在“ cakeblog / posts / index”(将“ www.example.com”调整为我的本地ServerName)上查看帖子。 '。 我很确定我遇到了某种mod_rewrite问题,但是我不知道是什么原因。 每当发生这种情况时,我的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

我知道该图标存在于我的webroot文件夹中,位于/ Users / bailey / Sites / cascade / extranet-cake / app / webroot。 如果我了解路由权,则Cakeblog / posts / index 应该是Post PostsController的控制器,而/ index应该是PostsController“ index()”中的操作/方法。 因此,似乎无法识别控制器?

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

(应用程序/模型/Post.php):

<?php

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

    }

?>

(app / Controller / PostsController.php):

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

?>

(应用程序/视图/帖子/index.ctp):

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

这是我第一次真正看到CakePHP,并且在其他任何帖子中都找不到解决方案,只是出于偶然原因怀疑有mod_rewrite问题。 有人对我缺少的东西有想法吗? 我也可以根据要求发布httpd.conf文件。

[解决了]

愚蠢的错误-原来我使用的不是app / webroot以外的子文件夹作为webroot。 一旦我更改了它,它就可以正常工作。

JeremyHarris在上面的注释中提供了一个与我默认的Webroot不同的替代方法,并在CakePHP文档中提供了支持:

http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Installation.html

谢谢大家的帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM