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

Owe*_*wen 8 cakephp

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

但是,如果我将调试更改为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'));
Run Code Online (Sandbox Code Playgroud)

我已经尝试删除所有缓存文件并删除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));

    }
Run Code Online (Sandbox Code Playgroud)

Owe*_*wen 11

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

if (Configure::read() == 0):
    $this->cakeError('error404');
endif;
Run Code Online (Sandbox Code Playgroud)

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

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

  • for cakephp 2.4.3上面的代码替换为if(!configure :: read('debug')):throw new NotFoundException(); 万一; 但问题仍然存在:P (2认同)