Your solution sometimes doesn't work. My code:
public function init(ModuleManager $moduleManager)
{
$sharedEvents = $moduleManager->getEventManager()->getSharedManager();
$sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e)
{
$controller = $e->getTarget();
$settingsManager = $controller->getSettingsManager();
$settingsManager->loadAll();
$skinName = $settingsManager->getValue('CURRENT_SKIN');
$skinDir = __DIR__ . DS . 'view' . DS . $skinName;
$serviceManager = $e->getApplication()->getServiceManager();
$templatePathResolver =
$serviceManager->get('Zend\View\Resolver\TemplatePathStack');
$templatePathResolver->setLfiProtection(false);
$templatePathResolver->setPaths(array($skinDir));
$viewModel = $e->getViewModel();
$viewModel->setTemplate('../'.$skinName.'/layout/layout');
$viewModel->setVariables(array('skin_name' => $skinName));
}, 100);
}
Currently when I visit the following URLs then all is ok:
http://zend2.localhost/application/test/add/id/99
http://zend2.localhost/application/test/showSettings
http://zend2.localhost/application/test/upload
http://zend2.localhost/acp //Another module.
But this URL:
http://zend2.localhost/
causes an error:
Warning:
include(D:\xampp\htdocs\zend2\module\Application\config/../view/application/index/index.phtml)
[function.include]: failed to open stream: No such file or directory in
D:\xampp\zend2\library\Zend\View\Renderer\PhpRenderer.php on line 461
# Time Memory Function Location
1 0.0008 335960 {main}( ) ..\index.php:0
2 0.1590 5591032 Zend\Mvc\Application->run( ) ..\index.php:14
3 0.2092 6922472 Zend\Mvc\Application->completeRequest( )
..\Application.php:310
4 0.2092 6922520 Zend\EventManager\EventManager->trigger( )
..\Application.php:326
5 0.2092 6922632 Zend\EventManager\EventManager->triggerListeners( )
..\EventManager.php:208
6 0.2096 6924192 call_user_func ( ) ..\EventManager.php:468
7 0.2096 6924208 Zend\Mvc\View\Http\DefaultRenderingStrategy->render( )
..\EventManager.php:468
8 0.2096 6924208 Zend\View\View->render( )
..\DefaultRenderingStrategy.php:128
9 0.2101 6925504 Zend\View\View->renderChildren( ) ..\View.php:197
10 0.2101 6926272 Zend\View\View->render( ) ..\View.php:232
11 0.2106 6927448 Zend\View\Renderer\PhpRenderer->render( )
..\View.php:204
But index.phtml file exists in given path!
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/ZF2-How-to-change-template-directory-tp4656995p4657283.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]