In my cakephp2 app I'm trying to pass a variable from my layout to Javascript.
I'm using the following code:
$test = array('a'=>'test');
$this->Js->set('data', json_encode($test));
echo $this->Js->writeBuffer();
Which results in the following HTML:
<script type="text/javascript">
//<![CDATA[
$(document).ready(function () {window.app = {"data":"{\"a\":\"test\"}"};});
//]]>
</script>
However when I try to reach window.app in my chrome console, I get the error "window.app is undefined".
Any ideas what I'm doing wrong?