在我的引导程序中,我检测用户所在的站点,然后发出布局更改和助手更改。基本上,如果 /public/site/ 中没有每个站点版本,则默认情况下存在的任何内容都是站点所依赖的
但是,我无法获得实际视图来依赖给它的路径或 /public/site 中的路径。
到目前为止,这是我的代码:
protected function _initSite() {
$this->bootstrap('db');
$db = $this->getPluginResource('db')->getDbAdapter();
$site_domain = strtolower($_SERVER['HTTP_HOST']);
//site
$query = $db->prepare("
SELECT s.*, so.*
FROM Site AS s
JOIN Site_Domain AS sd ON sd.site_id = s.id
JOIN Site_Option AS so ON so.site_id = s.id
WHERE sd.domain = :site_domain AND s.enabled = '1'
LIMIT 1
");
$query->bindValue('site_domain', $site_domain);
$query->execute();
$site = $query->fetch(PDO::FETCH_OBJ);
$query->closeCursor();
if (empty($site)) {
throw new exception('Unfortunately we were unable to load the site you requested via the domain you came to.');
}
//site definitions - we need to get away from defining global variables, so lazy
define('SITE_ID', $site->id);
//layout paths
Zend_Layout::startMvc(array(
'layout' => 'layout',
'layoutPath' => array(
APPLICATION_PATH.'/layouts/scripts/',
PUBLIC_PATH.'/site/'.$site->id.'/layouts/scripts/'
)
));
$view = $this->getResource('view');
//set site to view, we use alot of google anayltics code so
$view->site = $site;
//set title seperator
$view->headTitle($site->title)->setSeparator(' - ');
//add base path for layout overriding
$view->addBasePath(APPLICATION_PATH.'/modules/:module/views/');
//register view helper path
$view->addHelperPath('My/View/Helper/', 'My_View_Helper_');
//register partials fallback path
$view->addScriptPath(APPLICATION_PATH.'/layouts/partials');
//default partials path
$view->addScriptPath(PUBLIC_PATH.'/site/'.$site->id.'/layouts/partials/');//the default helpers
//bind objects to the registry
Zend_Registry::set('config', array('meta_description' => $site->meta_description, 'meta_keywords' => $site->meta_keywords));
Zend_Registry::set('site', $site);
return $site;
}
本质上,当登陆站点时,Zend_View 应该检查 /public/site/1/layouts/view/scripts/default/index/index.phtml 是否存在并使用它,如果不存在则使用 /application/modules/ default/views/scripts/index/index.phtml 并使用它。