How to use email layout in Zend Framework

I would like to use the layout for the letters I send. I am currently using the Zend Layout layout for web pages, but would also like the subject of my letters.

Here is what I have tried.

This is my function that sends an email

    $layout = Zend_Layout::getMvcInstance();
    $this->_view->render($template);
    $html = $layout->render('email');
    $this->setBodyHtml($html,$this->getCharset(), $encoding);
    $this->send();

Email layout is simple

    The email content
    <?php echo $this->layout()->content; ?>

When he comes through email, he just has ...

    The email content
+3
source share
2 answers

You are very close to your original method; however, you need to follow a few additional steps Zend_Layoutto get what you want:

$layout = Zend_Layout::getMvcInstance();
$layout->setLayout('email')
    ->disableLayout();
$layout->content = $this->_view->render($template);
$html = $layout->render();

$this->setBodyHtml($html, $this->getCharSet(), $encoding)->send();

Zend_Layout::disableLayout() $html. Zend_View Zend_Layout::content. .

Zend_Layout::setView Zend_View , . , , .

+5

Zend_View ?

0

Source: https://habr.com/ru/post/1755634/


All Articles