title: CakePHP 2.4 CakeEmail: How to access variable set using 'set()' instead of 'viewVars()'
body: <p>I'm upgrading a CakePHP site from 1.3 to 2.4 and the site sends out quite a few emails. In the original version I was using the old Cake Email Component and all the variables that had to be printed out in the email were passed using the controller's <code>set()</code> method.</p>
  
  <pre><code>// code in controller
  $this-&gt;set('my_var', 'whatever);
  </code></pre>
  
  <p>In the new version I am using the <code>CakeEmail</code> class which is slightly different. One of the differences is that the email's template can no longer 'see' these variables.</p>
  
  <pre><code>// code in View/Email template
  // works in 1.3 BUT NOT 2.4
  echo $my_var;
  </code></pre>
  
  <p><strong>Question 1:</strong> How do I change my View/Template code to access <code>$my_var</code>?</p>
  
  <p>I know I can pass variables to the View/Template using <code>CakeEmail::setVars()</code> but I want to avoid this as the structure of my code would make this a bit complicated (lots of nested functions).</p>
  
  <p>Alternatively, how do I get an array of all the variable set using <code>set()</code> to pass <code>viewVars()</code> just before the email is sent?</p>
  
  <pre><code>// How to do this in controller
  $my_vars = $this-&gt;???? // return array of all vars set so far
  $Email-&gt;viewVars($my_vars);
  $Email-&gt;send();
  </code></pre>