2009年1月30日星期五

Re: [fw-mvc] CSS Styles when using Dojo in Zend

-- Leonard Challis <gisterogue@gmail.com> wrote
(on Friday, 30 January 2009, 08:01 AM -0800):
> I have been playing with Dojo Forms in Zend and wanted to clear something up
> regarding their CSS styling.
>
> I believe we have everything running correctly -- it's usually a
> Zend_Dojo_Form with several Zend_Dojo_Form_Element_* instances, all set up
> programatically through Zend, i.e. without writing any JavaScript ourselves.
>
> Selecting the tundra theme, each time the page was loaded it would display
> the form with very minimal styling (in fact, mostly just styles from
> dijit.css). After tailing a few logs and having a look around in the
> different CSS files I decided to try putting class="tundra" in the html tag.
> This rendered the form with the Tundra styles nicely and was far prettier. I
> thought it was a little bit 'hacky' though and thought there must be a way
> to achieve this in a nicer fashion. After a bit of searching I found this
> little snippet from
> http://www.nabble.com/Re%3A-Zend-dojo.data-usage%2C-i-dont-understand-p20915966.html
> http://www.nabble.com/Re%3A-Zend-dojo.data-usage%2C-i-dont-understand-p20915966.html
>
>
> * Set the "tundra" class on either the <body> element, or a div
> surrounding the form. Let's try the latter:
>
> <?
> $this->dojo()->requireModule('dojox.data.QueryReadStore')
> ->addStylesheetModule('dijit.themes.tundra');
> ?>
> <div class="tundra">
> <?= $this->form ?>
> </div>
>
>
> This would suggest I would have to manually add the reference to the tundra
> class anywhere I was using Dojo Forms.
>
> Is this the accepted/correct way of setting each element to inherit the
> related theme styles?

Yes. The rationale is that you may not want the Dijit theme to apply to
your entire page, but may only want it selectively around certain areas
of your page -- forms, for instance, or accordion containers.

> And would it be a bad idea to have this set automatically like the
> other classes and javascript codes is when using Dojo in Zend?

The problem with this is that ZF actually doesn't know what your markup
will look like. While Zend_Dojo_Form will create a form, and could
potentially wrap it in a <div> with the dijit theme class set, it's also
entirely possible that you'll be setting the dijit theme later in the
request lifecycle -- for instance, in the layout file. As such, it
becomes very difficult -- if not impossible -- to do this automatically
in a consistent way.

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

没有评论: