I’m confused by this as I can’t find good documentation on how to do this, I have a jquery file called “index” located in my cakephp site folder at:
/app/webroot/js/index.js
I am trying to include it in my view with:
<?php
echo $javascript->link('index', false);
?>
but I get:
Fatal error: Call to a member function link() on a non-object in /var/www/site1/app/views/uiemails/index.ctp on line 4
I have also put this in my layout’s header:
<?php
//load the jQuery core
$javascript->link('jquery-1.4.2.min', false);
?>
I would appreciate any advice as to what I need to do to get this to work.. thanks
Edit
(I am using cakephp version 1.3.2
I have now tried:
putting this in my controller:
var $helpers = array('Form', 'Html');
then, in my view:
<?php
echo $this->html->script('index', false);
?>
but I still get:
Fatal error: Call to a member function script() on a non-object in /var/www/site1/app/views/uiemails/index.ctp on line 4
It looks like you’re forgetting to include the Javascript helper in your controller. The syntax also depends on which version of CakePHP you’re using. In 1.3.x, the Javascript helper has been deprecated and you would use the Html helper instead.
Your controller:
Your view:
or with CakePHP 1.3.x:
And in your filesystem:
/app/webroot/js/whatever.jsThe relevant documentation: