2010年2月26日星期五

Re: [fw-mvc] Dojo view helpers don't automatically "dojoRequire" their respective dijits

-- Nathan Garlington <garlinto@gmail.com> wrote
(on Thursday, 25 February 2010, 02:58 PM -0700):
> V1.10.1
>
> I have been refactoring my layouts and views to use the dojo view
> helpers, thinking that the helpers auto-required their respective
> dijits ala Zend_Dojo_Form, and quickly found out that this is not the
> case. Am I missing a step in configuring the view (other than
> dojoRequire-ing the dijits myself) that will enable this
> functionality, or is this a functionality that doesn't exist atm?

The functionality does exist (has since it was initially released), and
it does create the necessary dojo.require statements.

Please be aware, though, that if you are adding dijits to your _layout_,
you will need to be careful about the order in which you do so. Any
dijits created _after_ the dojo view helper has been echoed will not be
present.

As an example:

<html>
<head>
<?php echo $this->dojo() ?>
</head>
<body>
<?php $this->tabContainer()->captureStart('tabs') ?>
<?php $this->contentPane()->captureStart('main') ?>
<?php echo $this->layout()->content ?>
<?php echo $this->contentPane()->captureEnd('main') ?>
<?php echo $this->tabContainer()->captureEnd('tabs') ?>
</body>
</html>

In the above, the tab container and content pane should be aggregating
dojo.require statements for dijit.layout.TabContainer and
dijit.layout.ContentPane, respectively -- but since the dojo() view
helper was rendered _earlier_ in the script, they will not have been
aggregated yet when that happens.

The solution to this is to move these calls into another view script,
capture that content early in your layoute, and then echo it later.

content.phtml:
<?php $this->tabContainer()->captureStart('tabs') ?>
<?php $this->contentPane()->captureStart('main') ?>
<?php echo $this->layout()->content ?>
<?php echo $this->contentPane()->captureEnd('main') ?>
<?php echo $this->tabContainer()->captureEnd('tabs') ?>

layout.phtml:
<?php $content = $this->render('content.phtml') ?>
<html>
<head>
<?php echo $this->dojo() ?>
</head>
<body>
<?php echo $content ?>
</body>
</html>

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

没有评论: