MUY Belgium
MUY Belgium

Reputation: 2452

What has happened to javascript helper in cakePHP 2?

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,

Upvotes: 5

Views: 6821

Answers (2)

floriank
floriank

Reputation: 25698

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('...');

Upvotes: 9

Krishna
Krishna

Reputation: 1540

HtmlHelper::scriptBlock($code, $options = array())
    //Parameters:   

    $code (string) – The code to go in the script tag.
    $options (array) – An array of html attributes.

Upvotes: 0

Related Questions