-- 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/