我正在尝试为想要在Zend中发送的电子邮件创建一个正文变量。我能够加载部分并将其传递给我的模型,然后打包并发送它。我遇到的问题是我想将$ buyer传递给partial,以便使用帖子信息来填充电子邮件。
$ buyer包含我的所有发布数据。所以我在变量旁边有姓名,地址,电话号码和其他信息。 $ body2只是一个简单的HTML脚本,我希望能够在通过电子邮件发送之前填充来自$ buyer的信息。
// Get the Post Data
$buyer = $request->getPost();
// Creates the body for the email with the users information
$body2 = $this->view->partial('partials/enterpriseContact.phtml');
我尝试过 -
$body2 = $this->view->partial('partials/enterpriseContact.phtml', $buyer);
但那没用。我在控制器内工作,如果这有所作为。因此,完整的代码块看起来 -
// Get the Post Data
$buyer = $request->getPost();
// Create the body variable by loading the partial for the post card.
$body = $this->view->partial('partials/postcardEmail/eform1stpostcard.htm');
// Creates the body for the business email with the users information
$body2 = $this->view->partial('partials/enterpriseContact.phtml');
// New Model For Mail Client
$mailUs = new Model_MailUs(); // Instantiate the model to handle Emails
// Use that model to send the email, requires variables, who to send to, and body
$mailUs->sendMail($request->getPost(), 'guest', $body); // Sends an email to the user
$mailUs->sendMail($request->getPost(), 'link', $body2); // Sends an email to us
如何将变量放在Zend控制器的部分内?
答案 0 :(得分:2)
原则上,您应该可以使用:
// in controller or do this all the way back at bootstrap
$this->view->partial()->setObjectKey('mykey');
// in controller
$renderedContent = $this->view->partial('path/to/partial.phtml', $someData);
然后在部分本身:
<?php
$someData = $this->mykey
// now use $someData as you like
?>
但是,坦率地说,我通常最终会做更冗长的事情:
// In controller
$renderedContent = $this->view->partial('path/to/partial.phtml', array(
'mykey' => 'myval',
));
然后在部分:
<?php echo $this->mykey ?>
答案 1 :(得分:1)
$body2 = $this->view->partial('partials/enterpriseContact.phtml', array('buyer' => $buyer));
您必须使用单词数组,然后将变量集合设置为部分,如上所述。 然后,我可以通过在我的部分中键入echo $ this-&gt; buyer来访问变量。