CakePHP - TinyMceHelper 帮助程序错误:方法 TinyMceHelper::__name 不存在

发布于 2024-09-15 23:13:21 字数 2968 浏览 5 评论 0原文

所以我想实现 TinyMce 助手。我已按照 cakephp 面包店的说明进行操作,但仍然收到错误。

这是我的项目控制器中的助手数组:

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

这是我下载的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]

认为我错过了一个步骤这里?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寄人书 2024-09-22 23:13:21

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

如果您将助手从: 更新

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

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

您应该可以开始了。

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.

倾城泪 2024-09-22 23:13:21

我认为您在控制器中输入了助手名称。应该是:

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

和你的看法:

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

希望有所帮助。

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.

人海汹涌 2024-09-22 23:13:21

你应该这样做 cdburgess 建议,如果它不起作用,请确保您的 javascript 已加载,并编辑 Tinmce.php TinyMce 帮助程序的代码以正确加载 javascript,行如下所示:

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

You should do as cdburgess suggested, and if it does not work, make sure your javascripts gets loaded, and edit tinmce.php the TinyMce helper's code to properly load javascripts, line looks like this:

 $this->Javascript->link('/webroot/js/tiny_mce.js', false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文