未定义的变量:$ _SESSION

当我E_NOTICE尝试引用永不设置或未设置的会话(cake/libs/cake_session.php line

372)时,我在核心CakePHP文件中出现错误:

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。我有什么想念的吗?

当我尝试运行任何单元测试时,都会显示此错误。这是正常的吗?我已经清除了cake/目录,并用另一个目录(相同版本)替换了该目录,以确保我没有无意间修改了核心文件中的任何内容,但是仍然出现相同的错误。我不确定这是否只是框架中的缺陷或其他缺陷。

这是在命令行上运行测试的结果:

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中有一些多余的代码使事情变得混乱:

beforeFind和中afterFind

App::Import("Session");

$session = new CakeSession();

$sim_id = $session->read("Simulation.id");

我不知道 为什么 ,但这就是问题所在。删除这些行可以解决我遇到的问题。

以上是 未定义的变量:$ _SESSION 的全部内容, 来源链接: utcz.com/qa/424615.html

回到顶部