gpt4 book ai didi

php - Zend Framework 更改插件中的 View 位置

转载 作者:搜寻专家 更新时间:2023-10-31 21:44:51 27 4
gpt4 key购买 nike

我无法在任何地方找到我的问题的解决方案,无论是在 SO 上还是在实际的 zend 文档中。

基本上我有这个设置:

  1. 我创建了一个插件,它使用 Zend_Http_UserAgent 和 WURFL 来检测用户当前是否在使用手机。这是在预调度中完成的。这很好用

  2. 如果用户使用手机,我现在想更改 View 脚本目录。

  3. 理想情况下,在一个完美的世界中,我想尝试加载 View 的移动版本(如果存在),如果不存在,则加载默认 View 。但如果我至少能让 2 个工作,那我会很高兴。

我对如何做到这一点感到非常困惑。我已经看到我可以使用:

$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;$view->setBasePath(APPLICATION_PATH . '/mobile_views/');

但这似乎并没有达到我的预期,而且这种情况发生在 postDispatch 中,而我认为这种事情应该发生在 preDispatch 中?

这是我当前的插件:

<?php

类 SQ_Plugins_Mobile 扩展 Zend_Controller_Plugin_Abstract {

public function dispatchLoopStartup(Zend_Controller_Request_Abstract $flag) {

$bootstrap = Zend_Controller_Front::getInstance()->getParam("bootstrap");
$useragent = $bootstrap->getResource("useragent");
$device = $useragent->getDevice();

Zend_Registry::set("useragent", $useragent);
Zend_Registry::set("device", $device);

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 i wish to change the view path to be APPLICATION_PATH . "/mobile_views/"
* @todo Change the view script path
*/

}
}

public function postDispatch(Zend_Controller_Request_Abstract $request) {

/**
* Maybe i have to change the view script path here?
* @todo change the viewscript path if we're using a mobile
*/

// Get the current view
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;
$view->setBasePath(APPLICATION_PATH . '/mobile_views/');
echo "kl;kl;kjhkl;jhlkjhjklhkl;h k;hi";
}

最佳答案

如果它是页面的移动版本,您可以在操作中执行此操作。

$this->view->addBasePath('../application/views/mobile'); // Or whatever your path may be.

只是一个想法。

关于php - Zend Framework 更改插件中的 View 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5354466/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com