-
-
Save shadow-fox/ff8bdb089eac7c39271f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function onBootstrap(MvcEvent $e) | |
{ | |
$eventManager = $e->getApplication()->getEventManager(); | |
// load site | |
$eventManager->attach(MvcEvent::EVENT_ROUTE, function ($e) { | |
$serviceManager = $e->getApplication()->getServiceManager(); | |
$request = $e->getRequest(); | |
$siteMapper = $serviceManager->get('Application\Site\SiteMapper'); | |
$query = $siteMapper->buildQuery(); | |
$query->where(array('domain' => $request->getServer('HTTP_HOST'))); | |
$site = $siteMapper->fetchObject($query); | |
if (!$site) { | |
// TODO | |
} | |
// store the site in the service manager | |
$serviceManager->setService('Site', $site); | |
}); | |
// if a site was found, add its theme path | |
$eventManager->attach(MvcEvent::EVENT_RENDER, function($e) { | |
$serviceManager = $e->getApplication()->getServiceManager(); | |
$templatePathResolver = $serviceManager->get('Zend\View\Resolver\TemplatePathStack'); | |
$site = $serviceManager->get('Site'); | |
if ($site && $site->template_location) { | |
$templatePathResolver->addPath('./themes/'.$site->template_location.'/view'); | |
} | |
}, 100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment