I currently have the following setup in my module.
public function onBootstrap( EventInterface $e )
{
// You may not need to do this if you're doing it elsewhere in your
// application
$eventManager = $e->getApplication()->getEventManager();
$serviceManager = $e->getApplication()->getServiceManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach( $eventManager );
//TODO think about moving this to somewhere more appropriate
$renderer = $serviceManager->get( 'Zend\View\Renderer\PhpRenderer' );
$renderer->headTitle( 'uDare' )->setSeparator( ' - ' );
}
Is there a better way to do this or some other event that I should attach to?
I ask this because I’m hitting a problem when trying to use the Doctrine2ORMModule.
When I access the web page on my localhost all works fine. But when I run
./vendor/bin/doctrine-module --verbose
on the command line I get an error saying the following
PHP Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException'
with message 'Zend\ServiceManager\ServiceManager::get was unable to
fetch or create an instance for Zend\View\Renderer\PhpRenderer'
in /Library/WebServer/Documents/udare/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:407
Stack trace:
#0 /Library/WebServer/Documents/udare/modules/Web/Module.php(56): Zend\ServiceManager\ServiceManager->get('Zend\View\Rende...')
A good place for this probably would be in your
layout.phtml.If you need it to be configurable you could
layout.phtmlheadTitleview helperZend\Mvc\Service\ViewHelperManagerFactoryto get an idea about this.I haven’t tested 3. & 4. – I prefer 1. as this is a
view/phprendererspecific issue.