为什么我不能从Zend_controller的动作中调用global var?
我的代码:
require_once 'config.ini.php';
print_r($dbConfig); // in this line work OK
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
//$this->_redirect("index/add");
global $dbConfig;
header("Location:index/add");
print_r($_GLOBAL);// in this line var is undefined, but if I call wrong name of var like $dbConfig1 - I see error.
Maby Zend - 阻止全球变量?
答案 0 :(得分:0)
$GLOBALS
,而不是$GLOBAL
。
控制器类不包含在全局范围内,它包含在Zend_Controller_Dispatcher_Standard::dispatch
中。因此config.ini.php
中的变量在全局范围内不可用。
在init
public function init()
{
require_once 'config.ini.php';
$this->dbConfig = $dbConfig;
}
public function indexAction()
{
print_r($this->dbConfig);
...
}