0
目前,我有一個Zend Framework的應用程序,我把它與WURFL用戶代理集成,這樣我就可以移動和桌面版之間進行切換,我的插件駐留在庫默認和移動佈局Zend框架
<?php
class Zc_Controller_Plugin_TemplatePicker extends Zend_Controller_Plugin_Abstract
{
protected $useragent;
public function postDispatch(Zend_Controller_Request_Abstract $request)
{
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
$this->useragent = $bootstrap->getResource('useragent');
if($this->useragent->getDevice()->getType() == 'mobile')
{
Zend_Layout::getMvcInstance()->setLayout('mobile');
}
}
}
現在我在腳本文件mobile.phtml和layout.phtml 2點佈局,HW我可以使用一些控制器功能的,使得它可以利用用於移動的佈局,也我有自舉
protected function _initLayoutHelper()
{
// $front = Zend_Controller_Front::getInstance();
// $front->registerPlugin(new Zc_Controller_Plugin_TemplatePicker());
if(!stristr($_SERVER['REQUEST_URI'], '/admin')){
$this->bootstrap('frontController');
}
$layout = Zend_Controller_Action_HelperBroker::addHelper(new Zc_Controller_Action_Helper_LayoutLoader());
}
和佈局裝載機layoutloader代碼是
<?php
class Zc_Controller_Action_Helper_LayoutLoader extends
Zend_Controller_Action_Helper_Abstract
{
public function preDispatch(){
$bootstrap = $this->getActionController()->getInvokeArg('bootstrap');
$config = $bootstrap->getOptions();
Zend_Registry::set('config', $config);
$module = $this->getRequest()->getModuleName();
$controller = $this->getRequest()->getControllerName();
$action = $this->getRequest()->getActionName();
$layoutScript = "layout";
if (isset($config[$module]['resources']['layout']['layout'])) {
$layoutScript = $config[$module]['resources']['layout']['layout'];
}
$this->getActionController()->getHelper('layout')->setLayout($layoutScript);
}
}
我應該在哪裏調整,以便我可以有1個控制器類與2個單獨的layout.Thanks!
究竟什麼是你的問題?如果你想讓1個控制器擁有2個獨立的佈局,那麼修改'mobile.phtml'和'layout.phtml',以便它們不同......用PC訪問你的站點以查看佈局#2,用你的手機看# 1。這應該是你需要的一切,只要用戶代理探測插件工作正常。 – bububaba 2012-07-09 10:26:40
事情是工作..我可以從不同的設備獲得兩種不同佈局的視圖,我的問題是使用已經爲移動模板的默認控制器定義的控制器。 – d3bug3r 2012-07-09 10:31:12
我仍然不知道你的問題真的是什麼,抱歉... – bububaba 2012-07-09 12:33:21