1
這完全是一個奇怪的情況。
當用戶登錄時,我存放一些東西,使用下面的代碼:
$auth->getStorage()->write($authAdapter->getResultRowObject(array(
'username',
'avatar',
'status',
'role',
'id',
'email'
)));
然後我用下面的代碼在我的引導來獲得訪問變量:
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function preDispatch()
{
$this->frontController = Zend_Controller_Front::getInstance();
}
protected function _initBuildBase()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$this->view = $layout->getView();
// Set doctype
$this->view->doctype("XHTML1_TRANSITIONAL");
$this->view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
}
protected function _initLoader()
{
$adminLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Admin',
'basePath' => APPLICATION_PATH));
$autoLoader = Zend_Loader_Autoloader::getInstance();
$autoLoader->registerNamespace('MyApp_');
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => APPLICATION_PATH,
'namespace' => '',
'resourceTypes' => array(
'model' => array(
'path' => 'models/',
'namespace' => 'Models_'
),
'service' => array(
'path' => 'services/',
'namespace' => 'Services_'
),
'form' => array(
'path' => 'forms/',
'namespace' => 'Forms_'
),
),
));
return $autoLoader;
return $adminLoader;
}
protected function _initControllerPlugins()
{
$this->frontController->registerPlugin(new MyApp_Controller_Plugin_ApplicationSettings);
$this->frontController->registerPlugin(new MyApp_Controller_Plugin_LayoutLoader);
$this->frontController->registerPlugin(new MyApp_Controller_Plugin_LanguageSelector);
$this->frontController->registerPlugin(new MyApp_Controller_Plugin_Acl);
$this->frontController->registerPlugin(new MyApp_Controller_Plugin_Uploadify);
}
protected function _initActionHelpers()
{
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .'/views/helpers');
}
protected function _initRoutes()
{
$router = $this->frontController->getRouter();
$router->addRoute(
'crud',
new Zend_Controller_Router_Route('/:module/:controller/:action/:id', array('module' => 'admin', 'controller' => ':controller', 'action' => ':action', 'id' => ':id'))
);
$router->addRoute(
'pagination',
new Zend_Controller_Router_Route('/:module/:controller/index/:page', array('module' => 'admin', 'controller' => ':controller', 'action' => 'index', 'page' => ':page'))
);
$router->addRoute(
'pageUrl',
new Zend_Controller_Router_Route('/:page/:subpage', array('module' => 'default', 'controller' => 'index', 'action' => 'index', 'page' => ':page', 'subpage' => ':subpage'))
);
}
protected function _initLogin()
{
$this->auth = Zend_Auth::getInstance();
$this->view->user = $this->auth->getIdentity();
}
}
好,現在對於怪異的一部分:
當我使用
if($this->user->role == 'Administrator')
{
在我的layout.phtml中效果很好。但是,當我在一個index.phtml文件中使用相同的代碼,根據控制器加載它不起作用?!
陌生人的一部分是,它用來完美地工作,並根據用戶的角色使用它顯示不同的選項。
我在哪裏可以查找我的代碼中的錯誤?真的失去了檢查的地方。可能在某處改變了某些東西,但其他一切似乎都很好。
任何提示或指示將很棒!
您能否提供完整的Bootstrap功能?可能是一些bootstraping依賴問題(如視圖不bootstraped呢?) – Fge 2010-11-08 16:27:07
添加到我原來的帖子 – 2010-11-08 16:29:28
不知道這一點,但在引導佈局之前嘗試$ this-> bootstrap('view')。 – Fge 2010-11-08 16:40:05