2013-03-25 38 views
1

我正在嘗試使用cakePhp獲取TinyMce設置,並且唯一加載的是textarea。我從麪包店打算關閉這篇文章:Cakephp TinyMce

http://bakery.cakephp.org/articles/galitul/2012/04/11/helper_tinymce_for_cakephp_2

我查我的檔案拼寫和我的根目錄/ JS/tiny_mce和瀏覽器/輔助/ TinymceHelper.php。我是否需要在佈局中添加其他內容?

在我的控制,我有:

public $helpers = array('Html', 'Form', 'Session', 'Tinymce'); 

筆者認爲:

<?php echo $this->Tinymce->input('description', array(
    'label' => 'content'), 
    array('language' => 'en' 
     ), 
    'bbcode' 
    ); 
?> 
+1

請改善您的問題,嘗試解釋*什麼*不工作。描述您嘗試解決問題的方法(例如,是否包含TinyMce腳本,是否在瀏覽器控制檯中產生錯誤?)。在目前的狀態下,您的問題太廣泛,無法正確回答 – thaJeztah 2013-03-25 22:51:43

回答

4

我不能讓上面的幫手,所以我想這個插件通過CakeDC提出,解決了這一問題:https://github.com/CakeDC/TinyMCE

將文件解壓到app/plugin目錄後,您只需要在控制器中添加一個助手,該助手可能類似於:

public $helpers = array('TinyMCE.TinyMCE'); 

在/app/config/bootstrap.php文件我補充:

CakePlugin::load('TinyMCE'); 

... 

Configure::write('TinyMCE.configs', array(
'advanced' => array(
    'mode' => 'textareas', 
    'theme' => 'advanced', 
    'plugins' => 'emotions,spellchecker,advhr,insertdatetime,preview', 
    'theme_advanced_buttons1' => 'newdocument,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,fontselect,fontsizeselect,formatselect', 
    'theme_advanced_buttons2' => 'cut,copy,paste,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,|,code,preview,|,forecolor,backcolor', 
    'theme_advanced_buttons3' => 'insertdate,inserttime,|,spellchecker,advhr,,removeformat,|,sub,sup,|,charmap,emotions', 
    'width' => '700', 
    'theme_advanced_toolbar_location' => 'top', 
    'theme_advanced_toolbar_align' => 'left', 
    'theme_advanced_statusbar_location' => 'bottom', 
    'theme_advanced_resizing' => 'true' 
    ) 
) 
); 

你可以去TinyMCE的網站,並配置你喜歡的設置。

然後,一旦我有一個配置,並且在我的控制器添加的幫手,我說:

$this->TinyMCE->editor('advanced'); 

這將打開窗體上的文字區域到TinyMCE的編輯器,並從bootstrap.php中加載設置(注你還必須創建視圖上的textarea的輸入)

+1

我按照相同的過程,但無法獲取編輯器.. :( – 2013-08-19 12:18:23

+0

您可能需要仔細檢查您是否正在加載jquery,您正在使用cakephp 2.0+ ,並且有PHP5.2 +,並且確保你在bootstrap.php文件中添加了「CakePlugin :: load('TinyMCE');」,我剛纔編輯了我的答案,如果它仍然不起作用,一個新的問題,並告訴我你的代碼,我可能會幫助。評論下面的鏈接,如果你確實創建了一個問題 – Andrew 2013-08-19 16:55:15

+0

@Andrew ahm,你使用$ this-> Html-> script('/ TinyMCE/js/tiny_mce/tiny_mce.js',array( 'inline'=> false ));如下所示:https://github.com/CakeDC/TinyMCE/blob/master/Docs/Documentation/Setup.md? – Leah 2015-01-16 00:59:21

0

你需要知道的第一件事,是當前,教程中介紹的: http://bakery.cakephp.org/articles/galitul/2012/04/11/helper_tinymce_for_cakephp_2 是TinyMCE的3.x的我甚至沒有開始重新編寫適合4.x的代碼。更重要的是,教程使用了位於TinyMCE 3.x軟件包內的高級主題。來自官方網站的TinyMCE在

  1. 下載3.x的包:

    如果你使用CakePHP版本2.x和TinyMCE的它應該工作相當不錯http://www.tinymce.com/download/download.php

  2. 提取jscripts/tiny_mce目錄中的說明教程(對於app/webroot/js /)
  3. 將地址:public $helpers = array('Tinymce');添加到需要TinyMCE的每個控制器。
  4. 創建TinymceHelper。應用程序/查看/助手目錄中的PHP與代碼教程
  5. 裏面添加/編輯或任何是你給了與TinyMCE的領域的文件名創建字段,如:$this->Tinymce->input('ModelName.fieldname', $options = array(), $tinyoptions = array(), $preset = null);
    例如:
    echo $this->Tinymce->input('StaticPage.description', array('label' => 'Content'),array(), 'full');

我希望這可以幫助任何人:-)

+0

對不起,但你的方法不起作用,我完全按照你的入侵,但我的輸入字段加載正常情況下沒有TinyMCE幫手! – 2016-01-26 11:29:11

1

如果你的CakePHP的項目正在作曲家依賴管理的用戶,並且要包括CakeDC TincyMCE插件(https://github.com/CakeDC/TinyMCE),可以使用下面的配置,您composer.json

{ 
    "require": { 
     "cakedc/tiny-mce": "1.2.0" 
    }, 
    "extra": { 
     "installer-paths": { 
      "app/Plugin/TinyMCE": ["cakedc/tiny-mce"] 
     } 
    } 
} 

在這種情況下,我指定了一個自定義的「installer-paths」,因爲我的CakePHP應用程序駐留在/ app中,但我的composer.json位於根目錄中。如果沒有這個插件將最終在/插件/ TinyMCE而不是/ app /插件/ TinyMCE