0

我一直在查看用于修复 mod_rewrite 以用于 CakePHP(以及 CakePHP 文档)的帖子和一些 Google Groups 资料,但我似乎无法让 mod_rewrite 正常工作。

CakePHP 安装得很好,我得到了主页,我得到:在此处输入图像描述 然后我创建了一个模型 app/Model/Format.php:

<?php

    /**
     * File: app/Model/Format.php
     *
     * Format Model
     */
    class Format extends AppModel
    {
        var $name = 'Format';

        // <hasMany>
        var $hasMany = array(
                                'DVD' => array('className' => 'DVD')
                            );
    }

    ?>

带有方法的控制器 app/Controller/FormatsController.php:

function index()
    {           // Ignore Format -related- data
        $this->Format->recursive = 0;

        // Get all formats from the database that have a status of '1'
        $formats = $this->Format->find('all', array(
                                                        'conditions' => array('Format.status' => '1')
                                                    ));

        // Save the Formats in a variable for display from the View
        $this->set('formats', $formats);
    }

最后是 View app/View/Formats/index.ctp:

<?php
    // File: app/Views/Formats/index.ctp
?>

<div class='formats index'>

    <table>
        <thead> 
            <tr>
                <th> Format Name</th>
                <th> Description </th>
                <th> Actions </th>
            </tr>
        </thead>
        <tbody>
            <?php

            ?>
        </tbody>
    </table>

</div>

我在 cakephp 根目录、应用程序根目录、webroot 目录中的 .htaccess 文件都符合 CakePHP 建议 @ http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Installation.html

我还将 RewriteBase [path to my app dir] 添加到每个 .htaccess 文件中,因为 Google 小组中的某个人说它对他们有用。

但是,每当我尝试加载“cakecms/Formats/index”时,我都会得到:

在此处输入图像描述

有人对我缺少的东西有任何想法吗?我今天在一台新笔记本电脑上,这一切都在我的最后一台上工作。我必须错过一些东西......

4

2 回答 2

0

如果您有 url 重写问题,您通常会在默认主页上收到一条错误消息,而您没有,所以这可能不是问题。您应该检查的网址是cakecms/formats(注意小写“f”)。“索引”部分对于索引操作是可选的。

于 2013-02-27T12:24:27.190 回答
0

[解决了]

终于弄清楚我错过了什么。我从未更改过默认值

<Directory [DocumentRoot] />
....
</Directory>

我的 httpd.conf 文件中的目录。

当我在我的更具体的<Directory...>列表中允许覆盖时,我在我的默认 DocumentRoot 中拒绝它们。一旦我更改为AllowOverride Allhttpd.conf 中的默认 DocRoot 目录,Cake/Apache URL 路由就可以完美运行。

于 2013-03-01T00:47:18.280 回答