CakePHP-TinyMceHelper错误:方法TinyMceHelper::\名称不存在
所以我想实现TinyMce助手。我已经按照cakephp面包店的指示进行了操作,但仍然遇到了一个错误 这是“我的项目控制器”中的助手阵列:CakePHP-TinyMceHelper错误:方法TinyMceHelper::\名称不存在,php,cakephp,tinymce,helpers,Php,Cakephp,Tinymce,Helpers,所以我想实现TinyMce助手。我已经按照cakephp面包店的指示进行了操作,但仍然遇到了一个错误 这是“我的项目控制器”中的助手阵列: var $helpers = array('Form', 'Time', 'Crumb', 'Text', 'Tinymce'); 这是我下载的tinymce帮助程序: <?php class TinyMceHelper extends AppHelper { // Take advantage of other helpers var $helpe
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);
}
}
?>
是否认为我遗漏了一个步骤?我认为您在控制器中输入了帮助者的名称。应该是:
var $helpers = array('Form', 'Time', 'Crumb', 'Text', 'TinyMce');
在你看来:
echo $tinyMce->input('description');
希望对您有所帮助。您必须使用CakePHP 1.3。1.2中的表单帮助程序使用了
\u name
。在1.3中,由于某种原因更改为\u name
如果从以下位置更新辅助对象:
$tinyoptions['elements'] = $this->__name($fieldName);
到
您应该可以开始了。您应该按照建议进行操作,如果不起作用,请确保您的javascripts已加载,并编辑tinmce.php TinyMce helper的代码以正确加载javascripts,该行如下所示:
$this->Javascript->link('/webroot/js/tiny_mce.js', false);
嗨,贾马尔,不,还没修好。我更改了名字,然后不得不将助手的名字更改为tiny_mce。不管怎么说,现在我又收到了同样的错误消息哇,谢谢!我将在今晚回家后尝试它,它在CakePHP1.3上对我有效。我下载了helper并将其设置在一个干净的环境中,得到了相同的错误消息。我在CakePHP API文档上做了一些挖掘,发现了这个。快乐编码!
$tinyoptions['elements'] = $this->__name($fieldName);
$tinyoptions['elements'] = $this->_name($fieldName);
$this->Javascript->link('/webroot/js/tiny_mce.js', false);