2016-06-07 7 views
0

Warum kann ich nicht globale Variable aus der Aktion von Zend_controller aufrufen?Warum in Zend v1 Zend_Controller nicht Global var aufrufen

Mein Code:

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 - blockieren globalen Variablen?

Antwort

0
  1. $GLOBALS, nicht $GLOBAL.

  2. Die Controller-Klasse ist nicht im globalen Gültigkeitsbereich enthalten, sie ist in Zend_Controller_Dispatcher_Standard::dispatch enthalten. Daher sind Variablen von config.ini.php nicht im globalen Gültigkeitsbereich verfügbar.

  3. definieren diese Variable in init

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

Nein, es ist nicht zu arbeiten. Also mache ich es im Blick und arbeite auch nicht. Warum)? – yavafree

+0

http://zend-framework-community.634137.n4.nabble.com/Allowing-global-variables-with-Zend-Framework-td643899.html - dieser Mann spricht auch über – yavafree

+0

Ups, danke Sie haben Recht! Ich habe nicht gesehen, dass ich require_once in 2 Punkten benutze. Also nach der Verwendung der Anweisung requed - es ist Arbeit. Vielen Dank!!! – yavafree

Verwandte Themen