Skip to content

Commit

Permalink
Added support to set variables to be used in the render.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Apr 17, 2011
1 parent d5938dd commit 33ca64f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/Cake/Network/CakeEmail.php
Expand Up @@ -153,6 +153,13 @@ class CakeEmail {
*/
protected $_viewRender = 'View';

/**
* Vars to sent to render
*
* @var array
*/
protected $_viewVars = array();

/**
* Text message
*
Expand Down Expand Up @@ -651,6 +658,20 @@ public function viewRender($viewClass = null) {
return $this;
}

/**
* Variables to be set on render
*
* @param array
* @return mixed
*/
public function viewVars($viewVars = null) {
if ($viewVars === null) {
return $this->_viewVars;
}
$this->_viewVars = $viewVars;
return $this;
}

/**
* Email format
*
Expand Down Expand Up @@ -891,6 +912,7 @@ public function reset() {
$this->_layout = 'default';
$this->_template = '';
$this->_viewRender = 'View';
$this->_viewVars = array();
$this->_textMessage = '';
$this->_htmlMessage = '';
$this->_message = '';
Expand Down Expand Up @@ -1087,6 +1109,7 @@ protected function _render($content) {

$View = new $viewClass(null);
$View->layout = $this->_layout;
$View->viewVars = $this->_viewVars;
$msg = array();

$content = implode("\n", $content);
Expand Down
21 changes: 21 additions & 0 deletions lib/Cake/tests/Case/Network/CakeEmailTest.php
Expand Up @@ -518,6 +518,27 @@ public function testSendRender() {
$this->assertTrue((bool)strpos(DebugTransport::$lastHeader, 'To: '));
}

/**
* testSendRenderWithVars method
*
* @return void
*/
public function testSendRenderWithVars() {
$this->CakeEmail->reset();
$this->CakeEmail->transport('debug');
DebugTransport::$includeAddresses = true;

$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->layout('default', 'custom');
$this->CakeEmail->viewVars(array('value' => 12345));
$result = $this->CakeEmail->send();

$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'Here is your value: 12345'));
}

/**
* testReset method
*
Expand Down

0 comments on commit 33ca64f

Please sign in to comment.