为什么在 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 - 阻止全局变量?

  1. $GLOBALS,不是$GLOBAL

  2. 控制器class不包含在全局范围内,它包含在Zend_Controller_Dispatcher_Standard::dispatch中。因此来自 config.ini.php 的变量在全局范围内不可用。

  3. init中定义这个变量

    public function init()
    {
        require_once 'config.ini.php';
        $this->dbConfig = $dbConfig;
    }
    
    public function indexAction()
    {
        print_r($this->dbConfig);
        ...
    }