-- Peter Wansch <[EMAIL PROTECTED]> wrote
(on Tuesday, 02 September 2008, 09:41 PM -0700):
> I am planning to use Dijit widgets such as dateTextBox in my ZF application
> to benefit from client-side validating widgets. I don't want to use
> Zend_Form but mostly stay with HTML and Dijit-specific view helpers. Here is
> what I tried:
>
> First, in my controller action method, I set the helper path and enable Dojo
> after initView:
> $this->initView();
First, unless you've disabled the ViewRenderer, you do not need to call
initView() in your actions.
> $this->view->addHelperPath('Zend/Dojo/View/Helper',
> 'Zend_Dojo_View_Helper');
There's an easier way to do the above:
Zend_Dojo::enableView($this->view);
> $this->view->dojo()->enable();
>
> Second, in my layout script (html_header.phtml) I add the code to load Dojo:
>
> <?= $this->doctype('XHTML1_TRANSITIONAL') ?>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <?= $this->headTitle($this->page_title) ?>
> <?php $this->headMeta()->appendHttpEquiv('Content-Type', 'text/html;
> charset=UTF-8'); echo $this->headMeta(); ?>
> <?php
> $this->headLink()->appendStylesheet(Zend_Controller_Front::getInstance()->getBaseUrl()
> . '/css/common.css'); echo $this->headLink(); ?>
> <?= $this->headStyle() ?>
> <?php if ($this->dojo()->isEnabled()):
>
> $this->dojo()->setLocalPath(Zend_Controller_Front::getInstance()->getBaseUrl()
> .'/js/dojo/dojo/dojo.js')
> ->addStyleSheetModule('dijit.themes.tundra');
I would recommend the following: in your bootstrap, do this:
$view = new Zend_View;
Zend_Dojo::enableView($view);
$view->dojo()->setLocalPath($front->getBaseUrl() . '/js/dojo/dojo/dojo.js')
->addStyleSheetModule('dijit.themes.tundra')
->disable();
Then, in your layout, all you need to do is:
<?= $this->dojo() ?>
This simplifies your layout script and ensures that the setup is correct
from the beginning. The dojo() view helper will only generate any code
if it has been re-enabled by your application code later.
> echo $this->dojo();
> endif; ?>
> <?= $this->headScript() ?>
> </head>
> <body class="tundra">
>
> Third, in my view script that gets included later I add the following:
>
> <?php
> echo $this->dateTextBox(
> 'foo',
> '2008-07-11',
> array('required' => true)
> ); ?>
>
> When I render that view, all I get is the following in the source:
>
> <input id="foo" name="foo" value="2008-07-11" type="text" />
This is correct -- dijit creation is programmatic by default, which
means that you'll have standard, valid HTML by default.
> I checked the head URLs in the source and they are all correct:
>
> <head>
> <title>GGV</title>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
> <link href="/GGV/www/css/common.css" media="screen" rel="stylesheet"
> type="text/css" />
>
> <style type="text/css">
> <!--
> @import "/GGV/www/js/dojo/dijit/themes/tundra/tundra.css";
> -->
> </style>
>
> <script type="text/javascript" src="/GGV/www/js/dojo/dojo/dojo.js"></script>
>
>
> </head>
Hm -- looks like the dijit JS was not generated. You should be seeing
something like the following in an additional <script>:
dojo.requireModule("dijit.form.DateTextBox");
var zendDijits =
[{"id":"foo","params":{"required":"true","dojoType":"dijit.form.DateTextBox"}}];
Did you call Zend_Dojo_View_Helper_Dojo::setUseProgrammatic() at some
point? If so, what value did you pass it?
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend Framework | http://framework.zend.com/