-- Dan Rossi <[EMAIL PROTECTED]> wrote
(on Thursday, 09 August 2007, 05:50 PM +1000):
> Hi there, i setup this class, however there is no way to obtain the view
> class, or any kind of main config . Does it mean the view has to be
> setup again within the plugin class, doesnt seem so friendly to me,
> there is no description of how to start the view in something like like
> this.
Such a plugin makes one of the following assumptions:
* You've setup the view in your bootstrap or another plugin, and
placed it in Zend_Registry. As such, you're retrieve it from the
registry:
$view = Zend_Registry::get('view');
* You're using the ViewRenderer. As such, you can fetch it from the
ViewRenderer using this construct:
$view =
Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer')->view;
* You want a separate view so that you don't have any variable
pollution bleeding in from previous calls to the view. As such,
you'd instantiate your own view and setup its environment.
$view = new Zend_View();
Determine which of the above fits your situation and code accordingly.
> class TwoStepPlugin extends Zend_Controller_Plugin_Abstract
> {
>
> public function dispatchLoopShutdown()
> {
> $response = $this->getResponse();
> $segments = $response->getBody(true);
> // instantiate view in here somewhere...
> $view->assign($segments);
> $content = $view->render('index.phtml');
> $response->setBody($content); // overwrites named segments
> }
> }
>
>
> Matthew Weier O'Phinney wrote:
> >-- Dan Rossi <[EMAIL PROTECTED]> wrote
> >(on Tuesday, 07 August 2007, 11:54 PM +1000):
> >
> >>Hi there im having some problems which ive managed to hack up. Id like
> >>to be able to render a different template into a template variable
> >>called {content} so then all i need is one main index template and each
> >>controller / action can set a different content placeholder. The only
> >>way i can do it for the moment is rendering a template to a variable
> >>$this->view->content, would this be ok to do ?
> >>
> >> $this->tpl = $this->view->getEngine();
> >> $this->tpl->compile('sectionBody.html');
> >> $this->view->content =
> >> $this->tpl->bufferedOutputObject($this->view);
> >>
> >> $this->render("index", null, true);
> >>
> >>It basically gets the view engine which is the flexy template engine,
> >>compiles a section body as a string back to $this->view->content and it
> >>will display in the variable within the index view script. If there is a
> >>better way to do this let me know.
> >>
> >
> >One method I and others have used is to render to named segments in the
> >response object -- that's what the second argument to render is. That
> >way, you can collate all your various content from different actions in
> >the response object, and then pull it out to fill in another template.
> >
> >As an example, in your code above, I'd do something like:
> >
> > $this->render('sectionBody', 'section'); // renders to 'section'
> > // response segment
> >
> >And then create a dispatchLoopShutdown plugin:
> >
> > class TwoStepView extends Zend_Controller_Plugin_Abstract
> > {
> > public function dispatchLoopShutdown()
> > {
> > $response = $this->getResponse();
> > $segments = $response->getBody(true);
> >
> > // instantiate view in here somewhere...
> > $view->assign($segments);
> > $content = $view->render('index.phtml');
> > $response->setBody($content); // overwrites named segments
> > }
> > }
> >
> >Hope that makes sense.
> >
> >
>
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/