CakePHP - TinyMceHelper助手错误:方法TinyMceHelper :: __ name不存在

时间:2010-08-26 12:08:38

标签: php cakephp tinymce helpers

所以我想要实现TinyMce助手。我遵循了cakephp面包店的指示,但仍然出现错误。

这是项目控制器中的helpers数组:

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

这是我下载的小帮手:

<?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);
}
}
?>

这是我的添加视图,我想使用帮助器:

<?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');
?>

一切看起来都不错,但我收到了这个错误:

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

想想我在这里错过了一步?

3 个答案:

答案 0 :(得分:3)

您必须使用CakePHP 1.3。 1.2中的表单助手使用了__name。在1.3中,由于某种原因改为_name

如果您从以下位置更新帮助程序:

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

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

你应该好好去。

答案 1 :(得分:0)

我认为您错误地输入了控制器中的帮助程序名称。它应该是:

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

并在您看来:

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

希望有所帮助。

答案 2 :(得分:0)

你应该按cdburgess建议,如果它不起作用,请确保你的javascripts被加载,并编辑tinmce.php TinyMce帮助器的代码以正确加载javascripts,行看起来像这样:

 $this->Javascript->link('/webroot/js/tiny_mce.js', false);