gpt4 book ai didi

php - CakePHP - TinyMceHelper 帮助器错误:方法 TinyMceHelper::__name 不存在

转载 作者:搜寻专家 更新时间:2023-10-31 20:55:04 24 4
gpt4 key购买 nike

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

这是我的项目 Controller 中的 helpers 数组:

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

这是我要使用助手的添加 View :

<?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]

我觉得我漏掉了一步吗?

最佳答案

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

如果您从以下位置更新助手:

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

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

你应该可以开始了。

关于php - CakePHP - TinyMceHelper 帮助器错误:方法 TinyMceHelper::__name 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3574894/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com