わかった、
これは完全に奇妙な状況です。
ユーザーがログインすると、次のコードを使用していくつかのものを保存します。
$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ファイルで同じコードを使用すると、機能しませんか?!
奇妙な部分は、それが完全に機能し、ユーザーの役割に応じて異なるオプションを表示するために使用していたことです。
コードの間違いをどこで探すことができますか?チェックする場所で本当に迷子になりました。おそらくどこかで何かを変更しましたが、他のすべては正常に機能しているようです。
ヒントや指示は素晴らしいでしょう!