Jes*_*nce 2 php zend-framework
public function init(){
$this->view->user = Zend_Auth::getInstance()->getIdentity();
$this->view->siteName = Zend_Registry::get('config')->site->name;
$this->view->menu = $this->_helper->generateMenu(Zend_Auth::getInstance()->getIdentity());
$this->view->slogan = Zend_Registry::get('config')->site->slogan;
}
Run Code Online (Sandbox Code Playgroud)
这是所有模块中所有控制器中的init文件,我可以放置这个代码,以便执行每个请求,而不管被调用的模块/控制器是什么?
我宁愿建议你通过扩展Zend_Controller_Plugin_Abstract来编写一个插件,这是它的目的.
通过这种方式,您无需在控制器中的任何位置执行任何操作.然后,您可以使用注册表访问您的数据...
class My_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{
protected $_auth = null;
protected $_acl = null;
public function __construct (Zend_Auth $auth, Zend_Acl $acl)
{
$this->_auth = $auth;
$this->_acl = $acl;
}
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
//some code
}
}
Run Code Online (Sandbox Code Playgroud)
然后在你的bootstrap.php中
$this->_front->registerPlugin(new My_Controller_Plugin_Layout());
Run Code Online (Sandbox Code Playgroud)
http://framework.zend.com/manual/en/zend.controller.plugins.html
| 归档时间: |
|
| 查看次数: |
867 次 |
| 最近记录: |