Simple way to use TinyMCE 4.0.12 with Yii.

This extension lets you use TinyMCE on your Yii Project.

This extension simple publishes TinyMCE files to your sites /assets directory and registers them so they can be used.

I think this is a good approach because you don't need to learn anything specific to the extension and all the code required to display and configure the Textarea are in the view.


Yii 1.1 or above


Extract the release file under protected/extensions


In the view file that you want to use TinyMce add the following right before the <?php $this->endWidget(); ?> tag.

<?php $this->widget('application.extensions.tinymce.SladekTinyMce'); ?>
<?php $this->endWidget(); ?>

In the code above <?php $this->widget('application.extensions.tinymce.SladekTinyMce'); ?> is what publishes the assets (if they are not already published). is what actually used to configure the textarea and can be configured exactly as described in TinyMCE's Documentation

Here is a full example of a form that has two fields. *note that selector:'textarea' will apply to all text areas or you can specify individual textareas with selector: "textarea#YOUR_TEXTAREAS_ID"

/* @var $this ContractsController */
/* @var $model Contracts */
/* @var $form CActiveForm */
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
    // Please note: When you enable ajax validation, make sure the corresponding
    // controller action is handling ajax validation correctly.
    // There is a call to performAjaxValidation() commented in generated controller code.
    // See class documentation of CActiveForm for details on this.
)); ?>
    <p class="note">Fields with <span class="required">*</span> are required.</p>
    <?php echo $form->errorSummary($model); ?>
    <div class="row">
        <?php echo $form->labelEx($model,'contractName'); ?>
        <?php echo $form->textArea($model,'contractName',array('rows'=>6, 'cols'=>50)); ?>
        <?php echo $form->error($model,'contractName'); ?>
    <div class="tinymce">
        <?php echo $form->labelEx($model,'contractData'); ?>
        <?php echo $form->textArea($model,'contractData',array('rows'=>6, 'cols'=>50)); ?>           
        <?php echo $form->error($model,'contractData'); ?>
    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
<?php $this->widget('application.extensions.tinymce.SladekTinyMce'); ?>
    selector: "textarea#Contracts_contractName",
    menubar: false,
    width: 900,
    height: 300,
   toolbar1: "undo redo | bold | italic underline | alignleft aligncenter alignright alignjustify ", 
   toolbar2: "outdent indent | hr | sub sup | bullist numlist | formatselect fontselect fontsizeselect | cut copy paste pastetext pasteword | search replace ", 
<script type="text/javascript">
    selector: "textarea#Contracts_contractData",
    theme: "modern",
    width: 900,
    height: 300,
    plugins: [
         "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
         "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
         "save table contextmenu directionality emoticons template paste textcolor"
   content_css: "css/content.css",
   toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons", 
   style_formats: [
        {title: 'Bold text', inline: 'b'},
        {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
        {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
        {title: 'Example 1', inline: 'span', classes: 'example1'},
        {title: 'Example 2', inline: 'span', classes: 'example2'},
        {title: 'Table styles'},
        {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
<?php $this->endWidget(); ?>
</div><!-- form -->


Total 6 comments

#19733 report it
jsladek at 2016/01/09 02:10pm
This extension stopped working for me

I'm not sure if anyone else has had this extension stop working for them but I did. I was able to update the tinyMCE to the latest version and it was working again. There does appear to be some formatting changes so you might have to review the TinyMCE to check for changes with the way to use the new version. I zipped everything up and added it to the download section above. It is called Hope this helps.

#18904 report it
Finzaiko at 2015/02/02 06:09am
Inline mode not working

Hello jsladek, Why I use inline mode not working for try an bold button or something? in normal mode work properly

    selector: "textarea#ZGaugeMark_stencil_marking, textarea#ZGaugeMark_vibro_marking, textarea#ZGaugeMark_remarks",
    inline: true,
    menubar: false,
    width: 380,
    height: 130,
    plugins: "code",
    toolbar_items_size : 'small',
    toolbar1: "bold | italic underline | alignleft aligncenter alignright alignjustify code",

Thanks in advance.

#18229 report it
swedenfox at 2014/09/30 12:04pm
Working Perfect

Thank you for sharing it , i need your help , do you know why uneditable plugin seems to don't work ?

            selector: "textarea#Message_body",
            //theme: "simple",
            width: 900,
            height: 50,
            menubar: false,
            toolbar1: false,
            toolbar2: false,
            statusbar: false,
            panel: false,
            //language : 'it',
            plugins: "noneditable",
            noneditable_leave_contenteditable: true


it works with readonly:true, as parameter of tinymce . Again thnx

#16823 report it
Alex D. at 2014/04/01 06:28am
File upload

Thank you for extention. What is the best file (image) upload module to fit with this extention?

#16568 report it
GPM at 2014/03/06 05:42am
Highly Recommended !!!

Great extension and so easy to install.

Thank you :)

#16253 report it
dnanwn at 2014/02/03 02:05pm
Thanks for this extension

Everything ok

Leave a comment

Please to leave your comment.

Create extension