5

I have used this item and get this error :

Missing Helper
Error: JavascriptHelper could not be found.
Error: Create the class JavascriptHelper below in file: app/View/Helper/JavascriptHelper.php
<?php
     class JavascriptHelper extends AppHelper {
 }

Well indeed, this file does not exists, and I tried to use 'Js' in my helper array.

class myClassController expend AppController {
    var $helpers = array('Html', 'Js'); // and not 'Javascript');

In the code, the method $this->Javascript->codeBlock is called to add a javascript method (in the middle of the content instead of the header) but there is no $this->Js->codeBlockcodeBlock either.

$output .= $this->Js->codeBlock("datepick('" . $htmlAttributes['id'] . "','01/01/" . $options['minYear'] . "','31/12/" . $options['maxYear'] . "');");
    

Could you explain me what happened to the old Javascript helper or how to get the code working?

Is there an other helper which could work with CakePHP-2.0?

Cordially,

Community
  • 1
  • 1
MUY Belgium
  • 2,330
  • 4
  • 30
  • 46

2 Answers2

9

Have you read the migration guide? If not do that now: http://book.cakephp.org/2.0/en/appendices/2-0-migration-guide.html#xmlhelper-ajaxhelper-and-javascripthelper-removed

XmlHelper, AjaxHelper and JavascriptHelper removed The AjaxHelper and JavascriptHelper have been removed as they were deprecated in version 1.3. The XmlHelper was removed, as it was made obsolete and redundant with the improvements to Xml. The Xml class should be used to replace previous usage of XmlHelper.

The AjaxHelper, and JavascriptHelper are replaced with the JsHelper and HtmlHelper.

JsHelper JsBaseEngineHelper is now abstract, you will need to implement all the methods that previously generated errors.

So

$this->Js->codeBlock('...');

is now

$this->Html->codeBlock('...');
floriank
  • 25,546
  • 9
  • 42
  • 66
  • If XmlHelper is no longer there, it's assumed that it will work just fine then without doing public $helpers = array('Xml'); ? Is that right? – Leah Mar 15 '14 at 03:32
0
HtmlHelper::scriptBlock($code, $options = array())
    //Parameters:   

    $code (string) – The code to go in the script tag.
    $options (array) – An array of html attributes.
Krishna
  • 1,540
  • 2
  • 11
  • 25
  • Yes, but the notable thing is that the function is now in HtmlHelper and not any more in the JavascriptHelper which has been made obsolete. – MUY Belgium Aug 23 '12 at 08:18