Thanks Matthew.
After some fiddling around, I downloaded a copy of dojo from the
dojotoolkit.org web site and replaced the code that had shipped with ZF 1.6.
This fixed the "undefined node" problem and the button began to render.
I implemented all of the changes you recommended for the bootstrap and the
code is now cleaner in the layout.
But I have a related question. I have been trying to discover an optimal way
to hook-up dojo with elements programmatically. Currently, I'm not using the
form view helpers to render out the elements. I'm just hard coding the HTML.
Here is the significant portion of my index view script:
-------------
<?php $this->dojo()->javascriptCaptureStart() ?>
function alert1()
{
alert("go 1");
}
function alert2()
{
alert("go 2");
}
<?php $this->dojo()->javascriptCaptureEnd() ?>
<?php $this->dojo()->onLoadCaptureStart() ?>
function() {
var params1 = {
label: "I am button 1",
onClick: alert1
};
var params2 = {
label: "I am button 2",
onClick: alert2
};
new dijit.form.Button( params1, dojo.byId("button1"));
new dijit.form.Button( params2, dojo.byId("button2"));
}
<?php $this->dojo()->onLoadCaptureEnd() ?>
-------------
I then hard code a couple of buttons and give them the proper ids so that
dojo.byId can find them.
Is this a reasonable approach. Can you recommend something more streamlined,
cleaner, clearer? Are there emerging best practices?
Again, thanks for you time on this.
- ken
Matthew Weier O'Phinney-3 wrote:
>
> -- Ken Petri <[EMAIL PROTECTED]> wrote
> (on Thursday, 04 September 2008, 01:54 PM -0700):
>> I need some (I hope) very basic help in getting dojo up and working and
>> some
>> notion of how to do not have to use the declarative syntax would also be
>> great.
>
> First off, programmatic usage is the default, so nothing specialy you
> need to do there.
>
>> Here are the contents of the files in question:
>> bootstrap.php:
>> -------------
>> <?php
>> // ** Check to see if the environment is already setup **
>> if (isset($bootstrap) && $bootstrap) {
>> // Enable all errors so we'll know when something goes wrong.
>> error_reporting(E_ALL | E_STRICT);
>> ini_set('display_startup_errors', 1);
>> ini_set('display_errors', 1);
>>
>> set_include_path('../library');
>>
>> require_once "Zend/Loader.php";
>> Zend_Loader::registerAutoload();
>>
>> }
>>
>>
>> $frontController = Zend_Controller_Front::getInstance();
>> $frontController->setControllerDirectory('../application/controllers');
>> $frontController->setParam('env', 'development');
>>
>> // set up dojo helper
>> $viewRenderer =
>> Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
>> $viewRenderer->initView();
>> Zend_Dojo::enableView($viewRenderer->view);
>
> That's all you need to do there. I'd do the following additional stuff:
>
> $viewRenderer->view->dojo()->setLocalPath('/js/dojo/dojo/dojo.js')
>
> ->addStyleSheetModule('dijit.themes.tundra')
> ->disable();
>
>> //set up the layout
>> Zend_Layout::startMvc(array('layoutPath' =>
>> '../application/views/layouts'));
>> -------------
>>
>> layout.phtml:
>> -------------
>> <?php echo $this->doctype('XHTML1_STRICT'); ?>
>>
>> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
>> <head>
>> <?php echo $this->headTitle(); ?>
>> <?php echo $this->headMeta(); ?>
>> <?php echo $this->headLink(); ?>
>> <?php echo $this->headStyle(); ?>
>> <?php
>> if ($this->dojo()->isEnabled()) :
>> $this->dojo()->setLocalPath('/js/dojo/dojo/dojo.js')
>> ->addStyleSheetModule('dijit.themes.tundra');
>> echo $this->dojo();
>> endif;
>> ?>
>
> If you do as I suggest earlier, then all you need to do here is:
>
> <?php echo $this-dojo(); ?>
>
>> <?php echo $this->headScript(); ?>
>> </head>
>> <body class="tundra">
>>
>> <?php echo $this->layout()->content; ?>
>>
>> </body>
>> </html>
>> -------------
>>
>> and the index view, index.phtml
>> -------------
>> <?php
>> $this->dojo()->enable()
>> ->setDjConfigOption('parseOnLoad', true)
>
> Only set parseOnLoad if you need to --- i.e., if you're creating markup
> that defines dijits. It looks like you're doing that below, though.
>
>> ->requireModule('dijit.form.Button');
>> ?>
>>
>> <button dojoType="dijit.form.Button" id="helloButton">
>> Hello World!
>> <script type="dojo/method" event="onClick">
>> alert('You pressed the button');
>> </script>
>> </button>
>>
>> -------------
>>
>> What happens:
>> The page loads but I get a JavaScript error that says "node is undefined"
>> coming from bootstrap.js in the dojo library. The page is blank and,
>> looking
>> at the DOM's view of the HTML (using Firebug) I see only:<div
>> style="display: none;"/>
>
> Is the path to dojo correct? did dojo.js load? does FireBug report that
> dijit.form.Button loaded?
>
>> So, something is wrong, but I sure can't figure out what.
>>
>> Also, if someone has a fix for this, I would certainly appreciate an
>> example
>> of rendering out the same button example but programmatically. I would
>> rather not have all those proprietary attributes in the button code.
>
> First off, I wouldn't call it proprietary markup -- they're simply
> attributes, plain and simple.
>
> You can definitely do this programmatically, though:
>
> <?= $this->button('helloButton', 'Hello World!') ?>
> <? $this-dojo->onLoadCaptureStart() ?>
> function() {
> dojo.connect('helloButton', 'onclick', 'alert("You pressed the
> button")');
> }
> <? $this-dojo->onLoadCaptureEnd() ?>
>
> should do the trick (unsure of the alert statement in there, but I think
> it's correct).
>
>
> --
> Matthew Weier O'Phinney
> Software Architect | [EMAIL PROTECTED]
> Zend Framework | http://framework.zend.com/
>
>
--
View this message in context:
http://www.nabble.com/Basic-dojo-help-and-programmatic-dojo-example-tp19319767p19326278.html
Sent from the Zend Framework mailing list archive at Nabble.com.