我有我自己的抽象類來擴展Zend_Controller_Action,然後我的所有控制器擴展這個類。這裏是我的抽象類:Zend變量在視圖中不可訪問
<?php
abstract class CLG_Controller_Action extends Zend_Controller_Action
{
public $admin;
public $staff;
public $pool;
public $it;
//public $staff;
/**
*
* @var HTMLPurifier
*/
public $purifier;
public $action;
public $controller;
public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
{
parent::__construct($request, $response, $invokeArgs);
if(Zend_Registry::isRegistered('admin')) {
$this->admin = Zend_Registry::get('admin');
}
if(Zend_Registry::isRegistered('staff')) {
$this->staff = Zend_Registry::get('staff');
}
if(Zend_Registry::isRegistered('pool')) {
$this->pool = Zend_Registry::get('pool');
}
$this->purifier = Zend_Registry::get('purifier');
$this->controller = $this->getRequest()->getControllerName();
$this->action = $this->getRequest()->getActionName();
$this->registerViewObjects();
}
public function postDispatch()
{
/************************************************
* Prepare JS and CSS FILES FOR THIS REQUEST
************************************************/
$action = $this->_request->getActionName();
$controller = $this->_request->getControllerName();
$this->view->headScript()->appendFile('/js/jquery-2.0.2.min.js');
if (key_exists ($this->_request->getActionName(), $this->assets))
{
$action = $this->_request->getActionName();
foreach ($this->assets [$action] ['css'] as $css)
{
$this->view->headLink()->appendStylesheet ($css , 'print');
}
foreach ($this->assets [$action] ['js'] as $js)
{
$this->view->headScript()->appendFile($js);
}
}
$css = '/css/' . $controller . '/' . $action . '.css';
$js = '/js/' . $controller . '/' . $action . '.js';
$this->view->headLink()->appendStylesheet ($css , 'print');
$this->view->headScript()->appendFile($js);
}
private function registerViewObjects()
{
// THESE ARE ALWAYS AVAILABLE IN THE VIEW
$this->view->admin = $this->admin;
$this->view->staff = $this->staff;
$this->view->pool = $this->pool;
$this->view->controller = $this->controller;
$this->view->action = $this->action;
$this->view->purifier = $this->purifier;
}
}
然而,出於某種原因,在registerViewObjects()註冊的變量是不是在我的視圖文件訪問。
我在這裏錯過了什麼?
感謝
更新: 我應該說,我有行動擴展另一個類ActionMenu,和我的控制器,然後繼承了該類!
您確定ActionMenu :: __ construct()正在調用'parent :: __ construct()'? –