0

すべてのコントローラーで使用できる変数を登録したいと考えています。

class testController extends Zend_Controller_Action{

   public function testAction(){
      echo $this->testVar;
   }
...

どのように、どこで、この変数の内容を設定して、すべてのコントローラーでアクセスできるようにできますか?

4

2 に答える 2

0
class Default_Controller extends Custom_Controller_Abstract
{
    public function testAction()
    {
        $this->content = 'Test';
    }
}

class Index_Controller extends Custom_Controller_Abstract
{
    public function testAction()
    {
        echo $this->content;
    }
}

class Custom_Controller_Abstract extends Zend_Controller_Action
{
    public $content;
    public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array)
    {       
        parent::__construct($request, $response,$invokeArgs);
    }
}

お役に立てれば

于 2012-11-16T12:52:33.997 に答える
0

その変数を /public/index.php で宣言するだけです。すべてのアクションは index.php から開始されるため、index.php で U を宣言すると、グローバル変数として使用できます。

于 2013-10-05T12:32:16.033 に答える