我遇到了一个奇怪的问题:我过去使用Zend Dojo和Zend Form取得了很好的效果,但在我最近的项目中,Zend_Dojo拒绝启用,除非在视图中强制启用,而且即使这样也不会为我正在使用的dijit导入适当的库。下面是适用的代码:
Bootstrap.php:
protected function _initViewHelpers() {
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
$view->doctype('XHTML1_TRANSITIONAL');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
$view->headLink()->appendStylesheet('base.css');
}IndexController.php (摘自其他一些不相关的内容)
public function renderAction() {
$this->_helper->layout->setLayout('render');
//SNIP
if ($this->getRequest()->getParam("medialeadsource"))
{
$source = $this->getRequest()->getParam("medialeadsource");
$mls = $this->sourceService->getSourceByURI($source);
$this->view->source = $mls;
$form = new App_forms_Sweepstakes($mls->__get('id'), $mls->__get('layout'));
$this->view->form = $form;
switch($mls->__get('template')) {
case '1':
$this->_helper->viewRenderer('template-1');
break;
case '2':
$this->_helper->viewRenderer('template-2');
break;
case '3':
$this->_helper->viewRenderer('template-3');
break;
default:
$this->_helper->viewRenderer('template-1');
break;
}
$this->view->test = $this->sourceService->isURISlideshow($source);
$this->view->subheadline = $mls->__get('subheadline');
$this->view->body = $mls->__get('body');
Zend_Dojo::enableView($this->view);
Zend_Dojo::enableForm($form);
Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
//SNIP
}从template-1.phtml (到目前为止我为Dojo设置的唯一视图)。还要注意,对于这些特定的视图,布局本身没有任何内容,因此不会影响问题)。我只包含适用的部分,再次声明:
<?php
$this->dojo()->setDjConfigOption('usePlainJson',true)
->addStylesheetModule('dijit.themes.tundra');
echo $this->dojo();
?>
</head>
<body class="tundra">生成的代码如下:
<title>Test View Title</title>
</head>
<body class="tundra">所以很明显,什么都没发生..如果我将->enable()添加到视图中的dojo链中,则会得到以下结果:
<script type="text/javascript" src="primaryFunctions1.js"></script>
<style type="text/css">
<!--
@import "http://ajax.googleapis.com/ajax/libs/dojo/1.2.0/dijit/themes/tundra/tundra.css";
-->
</style>
<script type="text/javascript">
//<![CDATA[
var djConfig = {"usePlainJson":true,"parseOnLoad":true};
//]]>
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.2.0/dojo/dojo.xd.js"></script>
<title></title>
</head>
<body class="tundra">所以仍然没有dijit导入。我不知所措!
发布于 2011-01-05 21:17:19
我认为您的问题与导入/要求是在$form->render()之后创建的有关。你通常可以通过使用布局scripts.However来解决这个问题,现在我有时甚至在布局中也有borderContainers和其他dojo的东西,这迫使我把它放在文档的最后。
https://stackoverflow.com/questions/1358474
复制相似问题