I am attempting to create a body variable for an email I want to send in Zend. I am able to load the partial and pass it to my Model where it is then packaged and sent on its way. The issue I am having is that I want to pass $buyer into the partial in order to use the post information to populate the email.
$buyer contains all my post data. So I have the name, address, phone number, and other information in side that variable. $body2 is just a simple HTML script that I want to be able to populate with information from $buyer before emailing it.
// Get the Post Data
$buyer = $request->getPost();
// Creates the body for the email with the users information
$body2 = $this->view->partial('partials/enterpriseContact.phtml');
I tried doing –
$body2 = $this->view->partial('partials/enterpriseContact.phtml', $buyer);
But that did not work. I am working inside the controller if that makes a difference. The complete code block looks thus –
// 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
How do I put variables inside a partial from the controller in Zend?
In principle, you should be able to use:
Then in the partial itself:
But, frankly, I usually end up doing the more verbose thing:
Then in the partial: