-- David Mintz <[EMAIL PROTECTED]> wrote
(on Friday, 04 January 2008, 12:39 PM -0500):
> I know this has been asked and asked, and I have read the docs ad nauseum,
> but... will someone please put me out of my misery and spoon-feed me because I
> am still totally confused.
>
> Suppose you have different controllers and different modules and you want them
> to render the same view script?
>
> That is, I need thisModule/thisController/thisAction and thatModule/
> thatController/thatAction both to render this.phtml, which is located in the
> conventional place relative to thisModule. Thus, in thisModule/thisController
>
> function thisAction() {
> // works fine; this.phtml is autorendered
> }
>
>
> but in thatModule/thatController...
>
> function thatAction() {
> // how to render /path/to/app/thisModule/views/scripts/thisController/
> view.phtml ???
> }
First, you'll need to add the view script path for the 'thisModule'
module:
$thisModuleDir =
Zend_Controller_Front::getInstance()->getControllerDirectory('thisModule');
$this->view->addBasePath(dirname($thisModuleDir) . '/views');
Once you've done that, to render the particular view script:
$this->_helper->viewRenderer->renderScript('thisController/view.phtml');
You may also want to investigate moving the common functionality out to
a partial, which each view script could then acces. This way, you don't
have to jump through any hoops to access it -- just specify the module
as a parameter to the partial call.
Use this directory structure:
thisModule/
views/
scripts/
common.phtml
thisController/
this.phtml
thatModule/
views/
scripts/
thatController/
that.phtml
Then, in thisModule/views/scripts/thisController/this.phtml:
<?= $this->partial('common.phtml') ?>
and in thatModule/views/scripts/thatController/that.phtml:
<?= $this->partial('common.phtml', 'thisModule');
If you have variables necessary to the script, simply pass them in:
<!-- in thisModule, thisController/this.phtml: -->
<?= $this->partial('common.phtml', $this->commonVars) ?>
<!-- in thatModule, thatController/that.phtml: -->
<?= $this->partial('common.phtml', 'thisModule', $this->commonVars) ?>
Of course, partials are only in SVN currently. You can do similarly
using regular render() calls -- just make sure you have a common view
script path defined in your bootstrap so that both have access to the
view script. Let me know if you need help with that.
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/