私はWURFLを使ってデバイスのタイプを見つけました。また、モバイルビューのテンプレートを設定するためのプラグインを書いています。親切にコードの下を見てください。また、私はインデックスページを実行すると、私はタイプに基づいてビューを持っているapplication/layouts/scripts/
1.layout.phtml(デスクトップビュー) 2.mobile.phtml(モバイルビュー) の下に2つのテンプレートを作成していzendフレームワークを使用して異なるテンプレートパスを設定する方法は?
class ZC_Controller_Plugin_Mobile extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
$bootstrap = Zend_Controller_Front::getInstance()->getParam("bootstrap");
$useragent = $bootstrap->getResource("useragent");
$device = $useragent->getDevice();
Zend_Registry::set("useragent", $useragent);
Zend_Registry::set("device", $device);
/**
* @todo change this to be Mobile
*/
//echo $device->getType() . " is the type of device";
if($device->getType() == "mobile") {
/**
* Set the layout to be mobile, here we make sure we streamline what is loaded
* so as to not load things that arent needed.
*/
Zend_Layout::getMvcInstance()->setLayout("mobile");
/**
* Here we check to see if a mobile version of the template exists. if it does then we change the view suffix
* this allows us to load the mobile view if it exists and the defgault view if it doesnt.
*/
$base = APPLICATION_PATH . "/views/scripts/";
$mobile = $base . $request->getControllerName() . "/" . $request->getActionName() . ".mobile.phtml";
if(is_readable($mobile)) {
Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer')->setViewSuffix('mobile.phtml');
}
}
}
}
device.Nowファイル構造のこれまで
application/view/scripts/index/
1.index.phtml 2.index.mobile.phtml
のように今、私はO型に基づいてビューのパスを分離したい、とても良いですfデバイス。私はパスのようなものを持っています。
これは、ビューに基づいてサイトを開発するときにはより良いでしょう。
これに関する助言
おかげで使用することができます - > getParam( 'ブートストラップを'); $ view = $ this-> bootstrap-> getResource( 'view'); $ view-> setScriptPath(NULL); ($ request-> getControllerName()。 "/"。$ request-> getActionName()。 '); $ html = $ view-> render($ request-> getControllerName()。 .phtml '); Zend_Controller_Action_HelperBroker :: getExistingHelper( 'ViewRenderer') - > setViewBasePathSpec($ html); – mymotherland