如何在加载layout.phtml之前初始化db插件

时间:2012-06-05 08:52:11

标签: zend-framework layout load

我想在运行时创建菜单,具体取决于存储在db中的用户权限,我使用ACL进行扩展并撤消资源..

现在我想根据用户权限加载菜单。

这是我的navigation.phtml子页面

<?php

 $resourceLoader = new Application_Plugin_ResourceLoader();
 $namaspace = new Zend_Session_Namespace('Zend_Auth');

 $db = $registry::get('pmodel_Db');

 $roleId = $namaspace->id;
 $module = $resourceLoader->getUserModulesPrivileges($db, $roleId);

 var_dump($module);

?> 

我在bootstrap中加载了数据库pmodel_Db,我遇到了一个例外

 Notice: Undefined variable: registry in D:\wamp\www\zend_apps\inspect\application\layouts\scripts\navigation.phtml on line 6.

问题意味着包含navigation.phtml页面的layout.phtml在引导程序文件中的_initDbRegistry()方法之前加载..

如何在加载布局之前加载pmodel_Db?

1 个答案:

答案 0 :(得分:0)

你必须使用这个

 $db = Zend_Registry::get('pmodel_Db');
  

问题意味着包含的layout.phtml   navigation.phtml页面在_initDbRegistry()方法之前加载   引导程序文件

你错了,Zend不会在引导所需的资源之前发送请求。

您访问注册表的方式是错误的。