提问者:小点点

如何在ZF3中自定义标题标签和元标签描述?


我正在使用Zend Framework description,并试图像ZF2 Documentation建议的那样自定义标题标记,但我遇到了以下错误:

未捕获Zend\ServiceManager\Exception\ServiceNotFoundException:无法将服务“viewHelperManager”解析为工厂;您确定在配置过程中提供了它吗?在/var/www/html/basketmetrics/vendor/zendframework/zend servicemanager/src/servicemanager中。php:681堆栈跟踪:#0/var/www/html/basketmetrics/vendor/zendframework/zend servicemanager/src/servicemanager。php(757):Zend\ServiceManager\ServiceManager-

1/var/www/html/basketmetrics/vendor/zendframework/zend servicemanager/src/servicemanager。php(200):Zend\ServiceManager\ServiceManager-

这是我在Module.php的代码

namespace Stats;

class Module
{
    const VERSION = '3.0.2';

    public function getConfig()
    {
        return include __DIR__ . '/../config/module.config.php';
    }

    /**
     * @param  \Zend\Mvc\MvcEvent $e The MvcEvent instance
     * @return void
     */
    public function onBootstrap($e)
    {
        // Register a render event
        $app = $e->getParam('application');
        $app->getEventManager()->attach('render', array($this, 'setLayoutTitle'));
    }

    /**
     * @param  \Zend\Mvc\MvcEvent $e The MvcEvent instance
     * @return void
     */
    public function setLayoutTitle($e)
    {
        $matches    = $e->getRouteMatch();
        $action     = $matches->getParam('action');
        $controller = $matches->getParam('controller');
        $module     = __NAMESPACE__;
        $siteName   = 'BasketMetrics';

        // Getting the view helper manager from the application service manager
        $viewHelperManager = $e->getApplication()->getServiceManager()->get('viewHelperManager');

        // Getting the headTitle helper from the view helper manager
        $headTitleHelper   = $viewHelperManager->get('headTitle');

        // Setting a separator string for segments
        $headTitleHelper->setSeparator(' - ');

        // Setting the action, controller, module and site name as title segments
        $headTitleHelper->append($action);
        $headTitleHelper->append($controller);
        $headTitleHelper->append($module);
        $headTitleHelper->append($siteName);
    }    

}

我不知道我是做错了什么,还是我不能像ZF2那样做。

元标记“description”如何定制?


共1个答案

匿名用户

-