CakePHP - TinyMceHelper帮助程序错误:方法TinyMceHelper :: __ name不存在 [英] CakePHP - TinyMceHelper helper error: Method TinyMceHelper::__name does not exist

查看:160
本文介绍了CakePHP - TinyMceHelper帮助程序错误:方法TinyMceHelper :: __ name不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想实现TinyMce助手。我遵循cakephp面包店的指示,但仍然得到一个错误。



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

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

这是我下载的tinymce助手:

 <?php 
class TinyMceHelper extends AppHelper {
//利用其他帮助器
var $ helpers = array('Javascript'形成');
//检查是否已添加tiny_mce.js文件
var $ _script = false;

/ **
*添加tiny_mce.js文件并构造选项
*
* @param string $ fieldName字段的名称,例如Modelname不推荐使用.fieldname,Modelname / fieldname
* @param array $ tinyoptions此文本区域的TinyMCE属性数组
* @return string初始化TinyMCE区域的JavaScript代码
* /
function _build($ fieldName,$ tinyoptions = array()){
if(!$ this-> _script){
//我们不想每次都添加只需要一次
$ this-> _script = true;
$ this-> Javascript-> link('/ js / tiny_mce / tiny_mce.js',false);
}
//绑定字段的选项
$ tinyoptions ['mode'] ='exact';
$ tinyoptions ['elements'] = $ this-> __ name($ fieldName);
return $ this-> Javascript-> codeBlock('tinyMCE.init('。$ this-> Javascript-> object($ tinyoptions)。');');
}

/ **
*创建一个TinyMCE textarea。
*
* @param string $ fieldName字段的名称,例如Modelname.fieldname,Modelname / fieldname已弃用
* @param array $ options HTML属性数组。
* @param array $ tinyoptions这个textarea的TinyMCE属性数组
* @return string一个带有TinyMCE的HTML textarea元素
* /
function textarea($ fieldName,$ options = array(),$ tinyoptions = array()){
return $ this-> Form-> textarea($ fieldName,$ options)。 $ this-> _build($ fieldName,$ tinyoptions);
}

/ **
*创建一个TinyMCE textarea。
*
* @param string $ fieldName字段的名称,例如Modelname.fieldname,Modelname / fieldname已弃用
* @param array $ options HTML属性数组。
* @param array $ tinyoptions这个textarea的TinyMCE属性数组
* @return string一个带有TinyMCE的HTML textarea元素
* /
函数输入($ 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');
?>

一切正常,但我收到此错误:

 警告(512):方法TinyMceHelper :: __ name不存在[CORE / cake / libs / view / helper.php,line 154] 
解决方案

/ div>

您必须使用CakePHP 1.3。 1.2中的窗体助手使用 __ name 。在1.3中,由于某种原因改为 _name



如果您更新助手:

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

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

你应该很好。


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?

解决方案

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.

这篇关于CakePHP - TinyMceHelper帮助程序错误:方法TinyMceHelper :: __ name不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆