它对我有用。我在 Module.php 文件中配置了类似这样的视图助手。
//module/src/module/View/Helper/Authz.php //查看助手
use Zend\View\Helper\AbstractHelper;
class Authz extends AbstractHelper
{
public function isAllowed()
{
}
}
.
//模块.php
public function bootstrap(Event $e)
{
}
public function onBootstrap($e)
{
$app = $e->getApplication();
$serviceManager = $app->getServiceManager();
$serviceManager->get('viewhelpermanager')->setFactory('Authz', function ($sm) use ($e) {
return new Authz($sm); //view helper
});
}
// 部分 // 视图/布局/partials/leftnav.phtml
$userAllow = $this->Authz()->isAllowed();
// 在布局中,我在 leftnav.phtml 部分上方调用类似这样的内容。//查看/布局/layout.phtml
<?php echo $this->partial('partials/header', array('company_name' => 'CompanyName')); ?>
// 配置/module.config.php
'view_manager' => array(
'template_path_stack' => array(
'modulename' => __DIR__ . '/../view' ,
),
'strategies' => array(
'ViewJsonStrategy',
),
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'partials/header' => __DIR__ . '/../view/layout/partials/header.phtml',
'partials/leftnav' => __DIR__ . '/../view/layout/partials/leftnav.phtml',
'partials/contents-top' => __DIR__ . '/../view/layout/partials/contents-top.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
),