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.

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.


Reply via email to