What has happened to javascript helper in cakePHP 2?
Asked Answered
B

2

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,

Bowery answered 21/8, 2012 at 8:48 Comment(0)
G
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('...');
Grubbs answered 21/8, 2012 at 8:53 Comment(1)
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?Golanka
F
0
HtmlHelper::scriptBlock($code, $options = array())
    //Parameters:   

    $code (string) – The code to go in the script tag.
    $options (array) – An array of html attributes.
Frenchman answered 21/8, 2012 at 9:0 Comment(1)
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.Bowery

© 2022 - 2024 — McMap. All rights reserved.