I am trying to use the JsHelper::event method on my app, using the same code of the CookBook:
$this->Js->get('#element');
$ev = $this->Js->event('click', $this->Js->alert('hey you!'));
I try to run debug($ev)
, but it returns null
. In the controller, I am adding the helper like this:
var $helpers = array('Js' => array('Jquery'));
How do I get the JsHelper::event to work properly?
By default, the JsHelper buffers those calls, hence the null
return. You can return it inline if you want by setting 'buffer' => false
in your options.
See the book for more information: http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#javascript-engine-usage