cakephp路由 - pages_controller / home.ctp错误只有在debug = 0 [英] cakephp routing - pages_controller/home.ctp error only on debug=0

查看:253
本文介绍了cakephp路由 - pages_controller / home.ctp错误只有在debug = 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



然而,如果我将debug改为0,我得到以下错误:



我的router.php档案包含:

  Router :: connect('/',array('controller'=>'pages','action'=>'display ','home')); 
/ **
* ...并连接Pages控制器的其余网址。
* /
Router :: connect('/ pages / *',array('controller'=>'pages','action'=>'display'));

我已尝试删除所有缓存文件和删除CAKE cookie,其他操作按预期工作,直接访问,例如/ user,/ groups等。问题只发生在击中根'/'.



我使用cakephp 1.3.4和ACL + Auth。 / p>

编辑**我包含来自pages_controller.php 的默认()函数的代码

  / ** 
*显示视图
*
* @param mixed要显示的页面
* @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));

}


解决方案

答案是这么简单,这是令人尴尬的:在home.ctp有以下代码:

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

Configure :: read()默认情况下读取var debug - 因此如果调试设置,它会抛出此错误到0。



感谢本杰明把我放在正确的轨道上。蛋糕是美好的,同时令人不安,直到你知道基础!


When core.php debug is set at 1 or 2 and I browse to the root of my cakephp site I get expected result, the page served is correct, ie, PagesController default() action -> home.ctp

However if I change debug to 0 I get the the following error:

Error: The requested address '/' was not found on this server.

My router.php file contains:

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

I have tried deleting all cache files and removing CAKE cookies, and other actions work as expected when visited directly, eg, /user, /groups, etc. Problem only occurs when hitting the root '/'.

I am using cakephp 1.3.4 and ACL + Auth.

Edit ** I'm including the code for the default() function from pages_controller.php

/**
 * 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));

    }

解决方案

OK the answer is so simple it is embarassing: in home.ctp there is the following code:

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

Configure::read() by default read var debug - therefore it throws this error if debug is set to 0.

Thanks to Benjamin for putting me on the right track. Cake is wonderful and at the same time infuriating until you know the basics!

这篇关于cakephp路由 - pages_controller / home.ctp错误只有在debug = 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆