为什么在 Zend v1 Zend_Controller 中不调用 Global var
Why in Zend v1 Zend_Controller not call Global var
为什么我不能从 Zend_controller 的动作中调用全局变量?
我的代码:
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 - 阻止全局变量?
$GLOBALS
,不是$GLOBAL
。
控制器class不包含在全局范围内,它包含在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);
...
}
为什么我不能从 Zend_controller 的动作中调用全局变量?
我的代码:
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 - 阻止全局变量?
$GLOBALS
,不是$GLOBAL
。控制器class不包含在全局范围内,它包含在
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); ... }