为什么在CakePHP中将调试更改为0打破静态页面? [英] Why does changing debug to 0 in CakePHP break static Pages?

查看:157
本文介绍了为什么在CakePHP中将调试更改为0打破静态页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切都很好。没有错误。我将debug更改为0,所有的突然我的页面给出404错误,在我的日志中,我注意到我在我的应用程序控制器(以前工作正常)中声明的变量现在回到未定义。 / p>

奇怪。为什么要将调试更改为0会导致这种行为?



编辑:2012年4月18日 $ b

我在Pages控制器周围。之后的$ path = func_get_args();当我扔在一个die(print_r($ path))。使用调试1或2它返回我的主页上:

  Array 

[0] => home

当调试设置为0时为空。



这是我的一些路由:

  Router :: connect ,array('controller'=>'pages','action'=>'display','home')); 
Router :: connect('/ login',array('controller'=>'users','action'=>'login'));
Router :: connect('/ logout',array('controller'=>'users','action'=>'logout'));

Router :: connect('/ today',array('controller'=>'users','action'=>'today'));
Router :: connect('/ profile',array('controller'=>'users','action'=>'profile'));

$ staticPages = array(
'about',
'contact'
);

$ staticList = implode('|',$ staticPages);

Router :: connect('/:static',array(
'plugin'=> false,
'controller'=>'pages',
'action'=>'display'),array(
'static'=> $ staticList,
'pass'=> array('static')

);

从调试日志:

  2012-04-17 10:28:08注意:注意:注意(8):未定义的变量:loggedIn in [/ Users / conrad / Desktop / Creative / DEV / virtutrain / app / Header.ctp,line 3] 
trace:
include - APP / View / Elements / Header.ctp,第3行
View :: _ evaluate() - CORE / Cake / View / View。 php,line 908
View :: _ render() - CORE / Cake / View / View.php,line 872
View :: element() - CORE / Cake / View / View.php,line 412
include - APP / View / Layouts / default.ctp,第22行
View :: _ evaluate() - CORE / Cake / View / View.php,line 908
View :: _ render ) - CORE / Cake / View / View.php,line 872
View :: renderLayout() - CORE / Cake / View / View.php,line 527
View :: render Cake / View / View.php,line 471
Controller :: render() - CORE / Cake / Controller / Controller.php,行959
ExceptionRenderer :: _ outputMessage() - CORE / ExceptionRenderer.php,line 263
ExceptionRenderer :: error400() - CORE / Cake / Error / ExceptionRenderer.php,line 209
ExceptionRenderer :: render() - CORE / Cake / Error / ExceptionRenderer.php,行165
ErrorHandler :: handleException() - CORE / Cake / Error / ErrorHandler.php,第127行
[main] - [internal]

错误日志:

  2012-04-17 10:28:08错误:[NotFoundException]未找到
#0 / Users / conrad / Desktop / Creative / DEV / virtutrain / lib / Cake / View / View。 php(908):include()
#1 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/View/View.php(872):View-> _evaluate('/ Users / conrad / D ...',Array)
#2 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/View/View.php(463):View-> _render('/ Users / conrad / D ...')
#3 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/Controller/Controller.php(959):View-> render('about ',NULL)
#4 /Users/conrad/Desktop/Creative/DEV/virtutrain/app/Controller/PagesController.php(88):Controller-> render('about')
#5 [internal function]:PagesController-> display('about')
#6 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/Controller/Controller.php(485):ReflectionMethod-> ; invokeArgs(Object(PagesController),Array)
#7 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/Routing/Dispatcher.php(103):Controller-> invokeAction(Object CakeRequest))
#8 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/Routing/Dispatcher.php(85):Dispatcher-> _invoke(Object(PagesController),Object(CakeRequest) ,Object(CakeResponse))
#9 /Users/conrad/Desktop/Creative/DEV/virtutrain/app/webroot/index.php(96): Dispatcher-> dispatch(Object(CakeRequest),Object(CakeResponse ))
#10 {main}

再次... debug是at 1或2 ...



此安装是在MAMP上本地运行,但错误也发生在已在MediaTemple的网格服务或多或少的默认设置)。

解决方案

哇...这是坐在我的home.ctp页面视图,复制到所有其他页面:

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

主要wtf,但无论...解决问题。


Everything was working fine. No errors. I change debug to 0, and all of the sudden my pages are giving 404 errors, and in my logs I'm noticing that variables I declared in my app controller (that were working perfectly before) are now coming back as not defined.

Weirdness. Why would changing debug to 0 cause this kind of behaviour?

Edit: Apr 18, 2012

I poked around the Pages controller. After the "$path = func_get_args();" when I threw in a die(print_r($path)). With debug 1 or 2 it returns this on my home page:

Array
(
    [0] => home
)

It's blank when debug is set to 0.

Here's some of my routing:

Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
Router::connect('/logout', array('controller' => 'users', 'action' => 'logout'));

Router::connect('/today', array('controller' => 'users', 'action' => 'today'));
Router::connect('/profile', array('controller' => 'users', 'action' => 'profile'));

$staticPages = array(
        'about',
        'contact'
);

$staticList = implode('|', $staticPages);

Router::connect('/:static', array(
    'plugin' => false,
    'controller' => 'pages',
    'action' => 'display'), array(
        'static' => $staticList,
        'pass' => array('static')
    )
);

From the debug log:

2012-04-17 10:28:08 Notice: Notice (8): Undefined variable: loggedIn in [/Users/conrad/Desktop/Creative/DEV/virtutrain/app/View/Elements/Header.ctp, line 3]
Trace:
include - APP/View/Elements/Header.ctp, line 3
View::_evaluate() - CORE/Cake/View/View.php, line 908
View::_render() - CORE/Cake/View/View.php, line 872
View::element() - CORE/Cake/View/View.php, line 412
include - APP/View/Layouts/default.ctp, line 22
View::_evaluate() - CORE/Cake/View/View.php, line 908
View::_render() - CORE/Cake/View/View.php, line 872
View::renderLayout() - CORE/Cake/View/View.php, line 527
View::render() - CORE/Cake/View/View.php, line 471
Controller::render() - CORE/Cake/Controller/Controller.php, line 959
ExceptionRenderer::_outputMessage() - CORE/Cake/Error/ExceptionRenderer.php, line 263
ExceptionRenderer::error400() - CORE/Cake/Error/ExceptionRenderer.php, line 209
ExceptionRenderer::render() - CORE/Cake/Error/ExceptionRenderer.php, line 165
ErrorHandler::handleException() - CORE/Cake/Error/ErrorHandler.php, line 127
[main] - [internal], line ??

Error log:

2012-04-17 10:28:08 Error: [NotFoundException] Not Found
#0 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/View/View.php(908): include()
#1 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/View/View.php(872): View->_evaluate('/Users/conrad/D...', Array)
#2 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/View/View.php(463): View->_render('/Users/conrad/D...')
#3 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/Controller/Controller.php(959): View->render('about', NULL)
#4 /Users/conrad/Desktop/Creative/DEV/virtutrain/app/Controller/PagesController.php(88): Controller->render('about')
#5 [internal function]: PagesController->display('about')
#6 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/Controller/Controller.php(485): ReflectionMethod->invokeArgs(Object(PagesController), Array)
#7 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/Routing/Dispatcher.php(103): Controller->invokeAction(Object(CakeRequest))
#8 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/Routing/Dispatcher.php(85): Dispatcher->_invoke(Object(PagesController), Object(CakeRequest), Object(CakeResponse))
#9 /Users/conrad/Desktop/Creative/DEV/virtutrain/app/webroot/index.php(96): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#10 {main}

Again... not getting any errors whatsoever when debug is at 1 or 2...

This installation is being run locally on MAMP, but the errors also occur on the published site which is running on MediaTemple's grid service (with more or less default settings).

解决方案

Wow... this was sitting in my home.ctp Page view, and got copied to all other pages:

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

Major wtf, but regardless... problem solved.

这篇关于为什么在CakePHP中将调试更改为0打破静态页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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