2008年11月12日星期三

Re: [fw-mvc] Zend_Dojo AJAX Requests

-- frank.quosdorf <frank.quosdorf@totuba.com> wrote
(on Tuesday, 11 November 2008, 09:33 PM -0800):
> this seems to have been fixed in 1.7.0. What worked for me was to require all
> "possibly needed" dojo/dijit modules in Bootstrap. This means all modules
> must be required when the layout script is rendered (before the actual
> "content" for filling a dijit.dialog element is retrieved via Ajax call
> which is typically the case when invoking thickboxes):

Just a note: this is only necessary for elements that are rendered
*from* the layout script, not for elements rendered from your normal
action view scripts. The reason is that we're relying on a Two
Step/Composite view in order to aggregate all the dojo configuration
prior to rendering in the final layout script.

Two other solutions exist:

* In your layout script, render and capture any elements that have
dojo requirements prior to rendering the dojo() view helper:

<?php
$loginForm = $this->render('_loginForm.phtml');
?>
<?php echo $this->doctype() ?>
<html>
<head>
<title>Foo Bar</title>
<?php echo $this->dojo() ?>
</head>
<body>
<div id="header" class="tundra"><?php echo $loginForm ?></div>
...
</body>
</html>

* Create a Dojo layer that aggregates the various dojo.require
statements. So, in your example, you might have the following in
your js/custom/_base.js file:

dojo.provide("custom._base");
function() {
dojo.require("dojo.parser");
dojo.require("dijit.form.Button");
dojo.require("dijit.Dialog");
dojo.require("dijit.form.Textarea");
dojo.require("dijit.form.ValidationTextBox");
dojo.require("dijit.form.ComboBox");
dojo.require("dijit.form.DateTextBox");
}();

And then in your bootstrap, do this:

$view->dojo()->setLocalPath('/js/dojo/dojo.js')
->addLayer('/js/custom/_base.js')
->registerModulePath('custom', '../custom');

This will allow you to create a custom build trivially later, and
simplifies your bootstrap significantly.

>
> Zend_Dojo::enableView($view);
> Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
> $view->dojo()->setCdnBase(Zend_Dojo::CDN_BASE_GOOGLE)
> ->setCdnVersion("1.2")
> ->setCdnDojoPath(Zend_Dojo::CDN_DOJO_PATH_GOOGLE)
> ->requireModule("dojo.parser")
> ->requireModule("dijit.form.Button")
> ->requireModule("dijit.Dialog")
> ->requireModule("dijit.form.Textarea")
> ->requireModule("dijit.form.ValidationTextBox")
> ->requireModule("dijit.form.ComboBox")
> ->requireModule("dijit.form.DateTextBox")
> ->setDjConfigOption("parseOnLoad", true)
> ->addStyleSheetModule("dijit.themes.tundra");
> $view->dojo()->disable();
>
> I only found out after using the browser's JS console where an error was
> thrown I could not explain:
>
> Error parsing in _ContentSetter#Setter_DIV_0
>
> Turns out, this is thrown by Dojo's parser if one of the dijit elements'
> module needed to parse the element was not made available via
> requireModule("dijit.[module]") before using it:
>
> In a view script:
>
> <script type="text/javascript">
> function openThickbox(){
> dojo.xhrGet({
> // call module, controller, action and pass parameter format=json
> url: "/module/controller/action/format/json",
> load: thickboxCallback,
> error: thickboxError
> });
> }
>
> function thickboxCallback(data, ioArgs){
> dijit.byId("thickbox").setContent(data);
> dijit.byId("thickbox").show();
> }
>
> function thickboxError(data, ioArgs) {
> console.debug("error ...");
> }
> </script>
>
> < a href="#" onclick="openThickbox()">Open thickbox< /a>
>
> <div dojoType="dijit.Dialog" id="thickbox" title="Thickbox"></div>
>
>
> Matthew Weier O'Phinney-3 wrote:
> >
> > --
> >
> > The problem I alluded to is that Javascript will not execute <script>
> > tags returned by XHR requests. You can certainly write a handler for
> > JSON responses, however, that could do as you suggest; the difficulty
> > there would be if you want to mix HTML and JS. Additionally, you may
> > have some issues with encoding JS to insert into JSON until we get JS
> > expression support added to Zend_Json (this proposal is up for review
> > now, however, and may be included for 1.7.0).
> >
>
> --
> View this message in context: http://www.nabble.com/Zend_Dojo-AJAX-Requests-tp20047453p20454541.html
> Sent from the Zend MVC mailing list archive at Nabble.com.
>

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: