Text Editor Integration

Can anyone suggest any tutorial or guide to integrate textEditor (cKEditor or tinyMCE)?

Thanks in advance.

I don’t use existing extensions for TinyMCE. Instead I have a very lightweight widget:


class TinyMCE extends CInputWidget


    public $editorOptions = array();


    public function run()


        list($name, $id) = $this->resolveNameID();


        // Publishing assets.

        $dir = dirname(__FILE__);

        $assets = Yii::app()->getAssetManager()->publish($dir.DIRECTORY_SEPARATOR.'assets');

        $this->editorOptions['script_url'] = $assets.'/tiny_mce.js';


	// Registering javascript.

        $cs = Yii::app()->getClientScript();









	$this->htmlOptions['id'] = $id;



	    $html = CHtml::activeTextArea($this->model, $this->attribute, $this->htmlOptions);


	    $html = CHtml::textArea($name, $this->value, $this->htmlOptions);


        echo $html;



To don’t specify all parameters everytime I have some classes for different kinds of editors. Here is an example of a simple editor without any advanced buttons:


require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'TinyMCE.php';

class TinyMCE_Simple extends TinyMCE


    public $editorOptions = array(





        'theme_advanced_buttons1'=>'pasteword, separator, bold, italic, underline, separator, undo, redo, separator, code',
















All options correspond to the TinyMCE built-in options.

All you need now is to download TinyMCE jQuery package and put it into extensions/tiny_mce/assets directory.

To use this widget with CActiveForm, write the following code:

	<div class="row">


        $this->widget('application.extensions.tiny_mce.TinyMCE_Simple', array(



            'htmlOptions'=>array('style'=>'width: 100%; height: 350px;'),

        )); ?>


Hope, it will work for you :)

Beside andy_s suggestion, maybe this will help you.

I also don’t use an extension from Yii website, instead i created mine, having in mind the idea of driver based editors(too much said at this moment), so i have an extension called “editor” structured like:








For now i only use ckeditor, therefore a single "driver", but tiny_mce can easily be added.

So, in views/ckeditor/assets i keep all the ckeditor files (ckeditor.js etc)

In the render.php file, near assets folder, i keep the logic for generating the editor

The textEditorWidget.php is the widget that renders the editor.

// textEditorWidget.php



* Driver based loading of editors.

* This is just a starting point in this moment.


class TextEditorWidget extends CWidget{

    private $editor='ckeditor';

    public $models;

    public $clientOptions=array();


    public function init()






    public function run()



            throw new CHttpException(500,Yii::t('app',"Please provide an array of models")) ;




        foreach($this->models AS $model)



                throw new CHttpException(500,Yii::t('app',"The model params are not correct")) ;  



            foreach($model['attributes'] AS $attributeName=>$attributeOptions)


                $fieldName=CHtml::getActiveId($model['instance'], $attributeName);


















    * Just this for now.


    private function setOptions($options)








        return array_merge($defaults, $options, $this->getFileManager());



    private function parseOptions($options)



        foreach($options AS $key=>$value)











        return implode(",\n",$output);



    private function setScriptUrl()






    private function getFileManager()


        return array(









// the render.php file


<?php foreach($models AS $model):?>

    CKEDITOR.replace('<?php echo $model['fieldName'];?>',{

        <?php echo $model['options'];?>

        ,enterMode : CKEDITOR.ENTER_BR // avoid the FF BUG


<?php endforeach;?>

function getTextareaContent(textareaId){


        return ;


    return CKEDITOR.instances[textareaId].getData();



And i call the widget like:

<?php $this->widget('ext.editor.textEditorWidget',array(





                'prize'=>array('width'=>700, 'height'=>200),







The above call will create 3 editors for prize/how_to_enter/extra_info fields of the $model.

You can pass as many models as you need and as many fields as you need in a single widget instance(that’s the huge advantage, many extensions will need a widget call for each editor instance).

Also, the render.php file, gives you a javascript function (getTextareaContent) to get the editor content in case you are doing ajax submissions.

This can be a good starting point for you. Anyway, once this extension is done in my own CMS i will share it with everybody…but it will take some time.

It did the same way as you have mentioned. But shows error:

The asset "E:\xampp\htdocs\myProject\protected\extensions\tiny_mce\assets" to be published does not exist.

I have too downloaded the tinyMCE. Where shall I have to keep this folder?

I also tired this but displays error:

The asset "/views/ckeditor/assets/" to be published does not exist.

I slightly modified in view part during calling widgets :

instead of ext.editor.textEditorWidget I modified with application.extensions.editor.textEditorWidget. Similarly in textEditorWidget.php in line no.83

extensions\tiny_mce\assets directory should containt TinyMCE (jQuery version) files:

  • langs

  • plugins

  • themes

  • … etc

andy_s, it displays just a text box with out editor. It also shows the following error:

$("#Ad_body").tinymce is not a function

Make sure all assets are published. On my local (slow) machine sometimes it takes over 30 seconds (what is more than the default max execution time) :huh: Also remove ‘language’=>‘ru’ from TinyMCE_Simple.php, because if you don’t have this language, a textbox won’t be displayed.

Publish You mean generation of related files & directory inside assets?? If so then the Yii has automatically done it. All the files and directories are resided in assets/e412b135/

I have also changed the ‘language’=‘en’

Still same error :

Application Log[15:21:48.446][trace][system.db.CDbCommand] Querying SQL: SHOW COLUMNS FROM `tbl_ad`in E:\xampp\htdocs\socialsite\protected\modules\ads\controllers\AdsController.php (65)

in E:\xampp\htdocs\socialsite\index.php (13)

[15:21:48.450][trace][system.db.CDbCommand] Querying SQL: SHOW CREATE TABLE `tbl_ad`in E:\xampp\htdocs\socialsite\protected\modules\ads\controllers\AdsController.php (65)

in E:\xampp\htdocs\socialsite\index.php (13)

[url=""]index..../create (line 154)[/url]

$("#Ad_body").tinymce is not a function 		[url=""]anonymous[/url]()index..../create (line 144)

[url=""]anonymous[/url] ()jquery.js 			(line 282)[url=""]anonymous[/url]()jquery.js (line 199)

[url=""]anonymous[/url] ()jquery.js			(line 25)

[url=""]anonymous[/url] ()index..../create 		(line 144)

[url=""]anonymous[/url] ()jquery.js 			(line 447)

[url=""]anonymous[/url] ()jquery.js 			(line 875)


[url=""]index..../create (line 144)[/url]

Yes, I mean files under (in your case) assets/e412b135/ directory. Make sure there is jquery.tinymce.js file. Or you can better try to replace all directory files with original (from the downloaded archive) manually. Also check, how it works in other browsers…

[font=arial, sans-serif][size="3"]Спасибо, очень много.[/size][/font] andy_s

You are welcome, but better speak english (translators are not very smart) :D