0

Basically, I want to render a view and layout from a model. Don't ask me why.

First of all, the views work as intended and I'm loading them into a variable for my perverse use later on. I am also fully aware that I could always do partial scripts. It seems to be a valid fallback, but it just doesn't cut it.

What I want to do is to get the layout to work automatically just like in the case with controllers and views.

Right now I employ something like this:

// Class blablabla
$layout = new Zend_Layout();
$layout->enableLayout();
$layout->setView($view);

// Ugly url, I know, I'm experimenting and they work
$body = $layout->render('mailer/layout/mail');
$body .= $view->render('mailer/templates/' . $type . '.phtml');  

The problem is that $body contains the layout and only then the actual view. Any advice? What am I doing wrong?

John
  • 261
  • 1
  • 3
  • 16

2 Answers2

2

Assuming that your layout contains the default $this->layout()->content somewhere, you'd want this:

$layout->content = $view->render('...');
$body = $layout->render('...');

Source: http://www.wowww.ch/2009/03/16/zend-mail-avec-template-standardise-avec-zend-layout-et-zend-view/

smhg
  • 2,159
  • 19
  • 26
umpirsky
  • 9,902
  • 13
  • 71
  • 96
0

I think my first note would have to be that you're trying to use a hammer as a screwdriver. As I'm sure you know, in the MVC model the view is the rendering, and is logically distinct (separate) from the model. I'm not sure you're going to find a happy solution to this, since you're crossing the streams.

markh
  • 783
  • 4
  • 10
  • I am well aware how MVC works. This function serves to generate a phtml (human readable/easy editable) stream to use as an email body, stored in the db to be sent out by a simple process that controls the email flow. Yes, anyone can use helpers, but 500 $html .= 'blablabla'; rows is a horrible approach. I can already, as I said, successfully use views to fulfill my dark needs. What I would appreciate is the layout working in a satisfactory way. See this as a latent MVC to parallel the standard one. – John Jul 29 '09 at 20:08
  • What I'm trying to say is that while the cross screwdriver is superior, I need a straight one now. – John Jul 29 '09 at 20:12
  • Gotcha, and thanks for being cordial when I was verifying the obvious. Good luck with this, I'm definitely not a ZF guru, and this question begs for one. – markh Jul 29 '09 at 20:20