I am trying to find out what the best practice for using Dojo widgets in a
Zend MVC application is. 
The following works:

1) In my view script xxxx.phtml I have the following:
<?php

// Render common HTML header
echo $this->render('partials/html_header.phtml');

?>
<div>
<?= $this->dateTextBox('foo', '2008-07-11', array('required' => true)) ?>
<?= $this->dojo() ?>
<?= $this->render('partials/html_footer.phtml'); ?>

2) My partial html_header.phtml looks like this:

<?= $this->doctype('XHTML1_STRICT') ?>
<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() ?>
    <?= $this->dojo() ?>  
    <?= $this->headScript() ?> 
</head>
<body class="tundra">

3) In my controller base class in the init method I do this:

            Zend_Dojo::enableView($this->view); 
           
$this->view->dojo()->setLocalPath(Zend_Controller_Front::getInstance()->getBaseUrl()
. '/js/dojo/dojo/dojo.js')
                       ->addStyleSheetModule('dijit.themes.tundra')
                       ->disable();
4) When needed in the specific controller action method, I enable dojo:
    public function xxxxAction()
    {
        // Enable Dojo
        $this->view->dojo()->enable();        

This works, but the this->dojo in my header is pointless. It only includes
the main dojo.js. If I don't print this->dojo() after I declare my Dojo
widget in the view script, the dijit code :

<script type="text/javascript">
//<![CDATA[
dojo.require("dijit.form.DateTextBox");
    dojo.require("dojo.parser");
dojo.addOnLoad(function() {
    dojo.forEach(zendDijits, function(info) {
        var n = dojo.byId(info.id);
        if (null != n) {
            dojo.attr(n, dojo.mixin({ id: info.id }, info.params));
        }
    })
    dojo.parser.parse();
});
var zendDijits =
[{"id":"foo","params":{"required":"true","dojoType":"dijit.form.DateTextBox"}}];
//]]>

does not get generated. Somehow this does not look right. All the examples I
have seen just have the call to dojo() in their respective layout scripts.
Is that only when I use ZendLayout that the layout content gets parsed
first?
-- 
View this message in context: 
http://www.nabble.com/Where-to-put-tp19387497p19387497.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to