2010-08-26 59 views
3

所以我想實現TinyMce助手。我遵循cakephp麪包店的指示,但仍然出現錯誤。CakePHP - TinyMceHelper助手錯誤:方法TinyMceHelper :: __名稱不存在

這是傭工陣列在我的項目控制器:

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] 

想想我錯過了一步嗎?

回答

3

您必須使用CakePHP 1.3。 1.2中的表單助手使用了__name。在1.3中,出於某種原因改爲_name

如果您更新了幫手:

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

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

你應該是好去。

+0

哇謝謝!我會在今天晚些時候嘗試在我回家的時候 – iamjonesy 2010-08-27 14:17:40

+0

它在CakePHP 1.3上爲我工作。我下載了助手,並將其設置在一個乾淨的環境中,並得到了相同的確切錯誤信息。我對CakePHP API文檔做了一點挖掘,並發現了這一點。快樂的編碼! – 2010-08-27 14:29:12

+0

做到了!謝謝! – iamjonesy 2010-08-27 17:41:23

0

我想你錯誤地鍵入控制器中的助手名稱。它應該是:

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

,並在您的視圖:

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

希望有所幫助。

+0

嗨,賈馬爾,不,這不是固定的。我更改了名稱,然後必須將幫助程序的名稱更改爲tiny_mce。無論如何,現在我再次得到相同的錯誤消息 – iamjonesy 2010-08-27 08:11:11

0

你應該做的cdburgess建議,如果它不能正常工作,請確保您的JavaScript被加載,和編輯tinmce.php TinyMCE的助手的代碼正確加載JavaScript的,行看起來是這樣的:

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