views:

23

answers:

2

So I'm wanting to implement the TinyMce helper. I've followed instructions from the cakephp bakery but am still getting a error.

This is the helpers array in my project controller:

var $helpers = array('Form', 'Time', 'Crumb', 'Text', 'Tinymce');

This is the tinymce helper I downloaded:

<?php
class TinyMceHelper extends AppHelper {
// Take advantage of other helpers
var $helpers = array('Javascript', 'Form');
// Check if the tiny_mce.js file has been added or not
var $_script = false;

/**
 * Adds the tiny_mce.js file and constructs the options
 *
 * @param string $fieldName Name of a field, like this "Modelname.fieldname", "Modelname/fieldname" is deprecated
 * @param array $tinyoptions Array of TinyMCE attributes for this textarea
 * @return string JavaScript code to initialise the TinyMCE area
 */
function _build($fieldName, $tinyoptions = array()) {
    if (!$this->_script) {
        // We don't want to add this every time, it's only needed once
        $this->_script = true;
        $this->Javascript->link('/js/tiny_mce/tiny_mce.js', false);
    }
    // Ties the options to the field
    $tinyoptions['mode'] = 'exact';
    $tinyoptions['elements'] = $this->__name($fieldName);
    return $this->Javascript->codeBlock('tinyMCE.init(' . $this->Javascript->object($tinyoptions) . ');');
}

/**
 * Creates a TinyMCE textarea.
 *
 * @param string $fieldName Name of a field, like this "Modelname.fieldname", "Modelname/fieldname" is deprecated
 * @param array $options Array of HTML attributes.
 * @param array $tinyoptions Array of TinyMCE attributes for this textarea
 * @return string An HTML textarea element with TinyMCE
 */
function textarea($fieldName, $options = array(), $tinyoptions = array()) {
    return $this->Form->textarea($fieldName, $options) . $this->_build($fieldName, $tinyoptions);
}

/**
 * Creates a TinyMCE textarea.
 *
 * @param string $fieldName Name of a field, like this "Modelname.fieldname", "Modelname/fieldname" is deprecated
 * @param array $options Array of HTML attributes.
 * @param array $tinyoptions Array of TinyMCE attributes for this textarea
 * @return string An HTML textarea element with TinyMCE
 */
function input($fieldName, $options = array(), $tinyoptions = array()) {
    $options['type'] = 'textarea';
    return $this->Form->input($fieldName, $options) . $this->_build($fieldName, $tinyoptions);
}
}
?>

And this my add view that I want to use the helper on:

<?php
echo $form->create('Project');
echo $form->input('title', array('label' => 'Title'));
echo $form->input('website', array('label' => 'Website'));
echo $tinymce->input('description');
echo $form->input('language_id', array('label' => 'Language'));
echo $form->input('tags', array('type' => 'text'));
echo $form->end('Post project');
?>

Everything looks alright but I'm getting this error:

Warning (512): Method TinyMceHelper::__name does not exist [CORE/cake/libs/view/helper.php, line 154]

Think I'm missing a step here?

A: 

I think you mistyped the helper name in controller. It should be :

var $helpers = array('Form', 'Time', 'Crumb', 'Text', 'TinyMce');

and in your view :

echo $tinyMce->input('description');

Hope that help.

Jamal Aziz
hi Jamal, nope that's not fixed it. I changed the names then had to change the name of the helper to tiny_mce. did that anyway and now I getting the same error message again
iamjonesy
+1  A: 

You must be using CakePHP 1.3. The form helper in 1.2 used __name. In 1.3 it was for some reason changed to _name.

If you update the helper from:

$tinyoptions['elements'] = $this->__name($fieldName);

to

$tinyoptions['elements'] = $this->_name($fieldName);

You should be good to go.

cdburgess
wow thanks! I'll try that later on this evening when I'm home
iamjonesy
It worked for me on CakePHP 1.3. I downloaded the helper and set it up in a clean environment and got the same exact error message. I did a little digging on the CakePHP API documentation and found this. Happy coding!
cdburgess
that did it! thanks!
iamjonesy
No worries! Happy coding!
cdburgess