cakephp routing - pages_controller / home.ctp仅在debug = 0时出错

时间:2010-09-25 13:48:13

标签: cakephp

当core.php调试设置为1或2时,我浏览到我的cakephp网站的根目录,得到预期结果,所提供的页面是正确的,即PagesController default()action - > home.ctp

但是,如果我将debug更改为0,则会出现以下错误:

  

错误:请求的地址'/'是   在此服务器上找不到。

我的router.php文件包含:

    Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
/**
 * ...and connect the rest of 'Pages' controller's urls.
 */
    Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

我尝试删除所有缓存文件并删除CAKE cookie,其他操作在直接访问时按预期工作,例如/ user,/ groups等。只有在按下'/'时才会出现问题。

我正在使用cakephp 1.3.4和ACL + Auth。

编辑**我在pages_controller.php中包含default()函数的代码

/**
 * Displays a view
 *
 * @param mixed What page to display
 * @access public
 */
    function display() {

        $path = func_get_args();

        $count = count($path);
        if (!$count) {
            $this->redirect('/');
        }
        $page = $subpage = $title_for_layout = null;

        if (!empty($path[0])) {
            $page = $path[0];
        }
        if (!empty($path[1])) {
            $subpage = $path[1];
        }
        if (!empty($path[$count - 1])) {
            $title_for_layout = Inflector::humanize($path[$count - 1]);
        }
        $this->set(compact('page', 'subpage', 'title_for_layout'));
        $this->render(implode('/', $path));

    }

3 个答案:

答案 0 :(得分:11)

好的答案很简单就是尴尬:在home.ctp中有以下代码:

if (Configure::read() == 0):
    $this->cakeError('error404');
endif;

默认配置:: read()读取var debug - 因此如果debug设置为0,则会抛出此错误。

感谢本杰明让我走上正轨。蛋糕是美妙的,同时真气,直到你知道基础!

答案 1 :(得分:4)

imho这种行为是有道理的,因为如果您的应用程序投入生产,您将调试设置为0(有些事情告诉我,您不希望将 home 页面显示为您的输入页面)。页面控制器显示的home.ctp位于

./cake/libs/view/pages/home.ctp

您的安装。但是如果你正在制作中,你想要显示

中的静态页面

./app/views/pages

目录,这是页面控制器的任务。新蛋糕装置中该目录为空。

答案 2 :(得分:1)

我想更新cakephp版本2.4.3的代码。 如上面的cakephp版本代码替换为

if (!Configure::read('debug')):
  throw new NotFoundException();
endif;

当debug设置为'0'时,它会抛出异常。您可以使用以下代码使其正常运行:

if ((Configure::read('debug')==='')):
throw new NotFoundException();
endif;