Added support to set variables to be used in the render.

This commit is contained in:
Juan Basso 2011-04-17 17:22:20 -04:00
parent d5938dd3c4
commit 33ca64f505
2 changed files with 44 additions and 0 deletions

View file

@ -153,6 +153,13 @@ class CakeEmail {
*/
protected $_viewRender = 'View';
/**
* Vars to sent to render
*
* @var array
*/
protected $_viewVars = array();
/**
* Text message
*
@ -651,6 +658,20 @@ class CakeEmail {
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
*
@ -891,6 +912,7 @@ class CakeEmail {
$this->_layout = 'default';
$this->_template = '';
$this->_viewRender = 'View';
$this->_viewVars = array();
$this->_textMessage = '';
$this->_htmlMessage = '';
$this->_message = '';
@ -1087,6 +1109,7 @@ class CakeEmail {
$View = new $viewClass(null);
$View->layout = $this->_layout;
$View->viewVars = $this->_viewVars;
$msg = array();
$content = implode("\n", $content);

View file

@ -518,6 +518,27 @@ class CakeEmailTest extends CakeTestCase {
$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
*