未定义变量:$ _SESSION [英] Undefined variable: $_SESSION
问题描述
当我尝试引用一个永不设置或未设置的会话( cake / libs /)时,核心CakePHP文件中会出现
): E_NOTICE
cake_session.php line 372
I'm getting E_NOTICE
errors in a core CakePHP file when it tries to reference a never-set or unset session (cake/libs/cake_session.php line 372
):
function read($name = null) {
if (is_null($name)) {
return $this->__returnSessionVars();
}
if (empty($name)) {
return false;
}
$result = Set::classicExtract($_SESSION, $name);
}
我通过我的代码(在app /目录中)我找不到对 $ _ SESSION
或 session_destroy
的引用。我缺少任何东西?
I've done a search through my code (in the app/ directory) and I can't find references to $_SESSION
or session_destroy
. Am I missing anything?
当我尝试运行任何单元测试时,显示此错误。这是正常吗?我清除了 cake /
目录,并用另一个(同一版本)替换它,以确保我没有无意中修改了核心文件中的任何内容,但是我仍然得到相同的错误。我不确定这是否只是框架中的缺陷或其他问题。
This error shows up when I try to run any unit tests. Is this...normal? I've cleared out the cake/
directory and replaced it with another one (same version) just to make sure that I hadn't inadvertently modified anything in the core files, but I still get the same error. I'm not sure if this is just a flaw in the framework or something else.
EDIT
以下是在命令行上运行测试的结果:
Here are the results of the test run on the command line:
Welcome to CakePHP v1.3.11 Console
---------------------------------------------------------------
App : app
Path: /var/www/program/app
---------------------------------------------------------------
CakePHP Test Shell
---------------------------------------------------------------
Running app case models/owners_equity
E_NOTICE: Undefined variable: _SESSION in /var/www/program/cake/libs/cake_session.php on line 372
E_NOTICE: Undefined variable: _SESSION in /var/www/program/cake/libs/cake_session.php on line 372
ERROR->Unexpected PHP error [Undefined variable: _SESSION] severity [E_NOTICE] in [/var/www/program/cake/libs/cake_session.php line 372]
in testGenerateOwnerWithdrawals
in BalanceTestCase
in /var/www/program/app/tests/cases/models/owners_equity.test.php
ERROR->Unexpected PHP error [Undefined variable: _SESSION] severity [E_NOTICE] in [/var/www/program/cake/libs/cake_session.php line 372]
in testGenerateOwnerWithdrawals
in BalanceTestCase
in /var/www/program/app/tests/cases/models/owners_equity.test.php
推荐答案
正在混乱的AppModel:
Turned out there was some extra code in the AppModel that was messing things up:
在 beforeFind
和 afterFind
:
App::Import("Session");
$session = new CakeSession();
$sim_id = $session->read("Simulation.id");
我不知道为什么,但那是什么问题。删除这些行解决了我遇到的问题。
I don't know why, but that was what the problem was. Removing those lines fixed the issue I was having.
这篇关于未定义变量:$ _SESSION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!