Yii 1.1: ckeditor-integration

CKEditor Integration
27 followers

This extension helps you to integrate CKEditor (next generation of FCKEditor) in your Yii application.

Screenshot

Note that CKEditor is not included in this extension, You can Download CKEditor form its official site and use it with this extension in your applications.

Resources

Documentation

Requirements

  • Yii 1.0 or above
  • CKEditor 3.4 or above

Installation

  • Extract the release file under protected/extensions
  • Download and extract CKEditor in your application root folder

Usage

See the following code example:

$this->widget('ext.ckeditor.CKEditorWidget',array(
  "model"=>$pages,                 # Data-Model
  "attribute"=>'content',          # Attribute in the Data-Model
  "defaultValue"=>"Test Text",     # Optional
 
  # Additional Parameter (Check http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html)
  "config" => array(
      "height"=>"400px",
      "width"=>"100%",
      "toolbar"=>"Basic",
      ),
 
  #Optional address settings if you did not copy ckeditor on application root
  "ckEditor"=>Yii::app()->basePath."/../ckeditor/ckeditor.php",
                                  # Path to ckeditor.php
  "ckBasePath"=>Yii::app()->baseUrl."/ckeditor/",
                                  # Realtive Path to the Editor (from Web-Root)
  ) );

if you need full details of configuration parameters, please visit CKEditor API.

Change Log

October 8, 2010

  • Initial release.

Total 15 comments

#7447 report it
ECNU长弓 at 2012/03/23 03:14am
3q

It is a good extension. Thanks

#6626 report it
Rajcsányi Zoltán at 2012/01/23 05:31am
modell array

I use a form with model array.

// ...
  "model"=>$pagesLang,
   "attribute"=>'[$key][pgtext]',
  // ...

The widget render:

PagesLang[[1][pgtext]]

But I need:

PagesLang[1][pgtext]

Because my controller works:

foreach ($this->_model->pagesLangs as $key=>$pagesLang) {
    $pagesLang->attributes = $_POST['PagesLang'][$key];
    $pagesLang->save(false);
  }

I can modify ext/view/CKEditorView.php to:

// $oCKeditor = new CKeditor(get_class($model).'['.$attribute.']');
  $oCKeditor = new CKeditor(get_class($model).$attribute);
 
  // ...
 
  // $oCKeditor->editor(get_class($model).'['.$attribute.']',$defaultValue);
  $oCKeditor->editor(get_class($model).$attribute,$defaultValue);

I don't know it is good or not, but works...

#6418 report it
Sampa at 2012/01/09 08:12am
Flawless!

I've tried a bunch of extentsions on this site, many is awesome but this one Is flawless. Simple and powerfull:) I've not had a single problem with this on the entire time. I just create new crud operations with gii and my textareas becomes powerfull ck editors instead:)

I've had it installed for a while but its not until now when I'm fixing the individuall text formatting / looks on 20+ pages with text that I realise how awesome it is to have it installed.

#4631 report it
izepstan at 2011/07/27 10:54am
upload ext

Hi,

Nice wrap. Is there a upload ext. which works with this?

#4001 report it
vimanaboy at 2011/05/25 09:21pm
2 ckeditor windows, one loaded via AJAX

Hi, is there a way to add a second CKeditor window, loaded through ajax with its own save button (ajax save - different model) ?

i'm pulling my hair out and can't make it work. the ckeditor window loads just ok and loads the neccessary data (it's filled with content correctly) but when i hit SAVE, the new ckeditor window content is not saved. when iswitch back to a normal form, it's saved as it should.

anyone went through something like this?

#3767 report it
warden at 2011/05/06 06:42am
model should get attribute

indeed, the Widget should do (line 73):

if(!isset($this->defaultValue)){
            $attr = $this->attribute;
            $this->defaultValue = $this->model->$attr;
        }
#3754 report it
banago at 2011/05/05 07:00am
Default value

@swiftgaruda: check out this post http://www.yiiframework.com/forum/index.php?/topic/9341-ckeditor-widget-in-a-cactiveform/

I had to set the value of the model attribute to the defaultvalue:

$defaultvalue = $model->content_field 
 
                $this->widget('ext.ckeditor.CKEditorWidget',array( 
 
                "model"=>$model,                 # Data-Model 
                "attribute"=>"content_field",          # Attribute in the Data-Model 
                "defaultValue"=>$defaultvalue,     # Optional
#3752 report it
Daniel Goldberg at 2011/05/04 08:37pm
Attribute data not showing up (I patched it in my project). Did I miss a step?

I'm using latest Yii 1.1.7 and [url="http://www.yiiframework.com/extension/ckeditor-integration"]ckeditor-integration[/url]. I setup ckeditor as per the directions on the extension page =>

[code] <?php $base = Yii::app()->request->baseUrl; $this->widget('ext.ckeditor.CKEditorWidget', array( "model"=>$event, "attribute"=>'description', 'config'=>array( 'width'=>'600px', 'filebrowserBrowseUrl' => $base.'/filemanager/index.html', ), )); ?> [/code]

But when the editor loads, the attribute doesn't come up.

I patched extensions/ckeditor/views/CKEditorView.php to make it work =>

keditor/views/CKEditorView.php 44a45,48

// pull model data into area $defaultValue = $model->$attribute;

[b]Did I miss something?[/b]

I submit this as a patch on the ext, but I'm still too green around the ears.

Thanks in advance, Daniel

#3751 report it
Daniel Goldberg at 2011/05/04 08:37pm
Attribute data not showing up (I patched it in my project). Did I miss a step?

I'm using latest Yii 1.1.7 and [url="http://www.yiiframework.com/extension/ckeditor-integration"]ckeditor-integration[/url]. I setup ckeditor as per the directions on the extension page =>

[code] <?php $base = Yii::app()->request->baseUrl; $this->widget('ext.ckeditor.CKEditorWidget', array( "model"=>$event, "attribute"=>'description', 'config'=>array( 'width'=>'600px', 'filebrowserBrowseUrl' => $base.'/filemanager/index.html', ), )); ?> [/code]

But when the editor loads, the attribute doesn't come up.

I patched extensions/ckeditor/views/CKEditorView.php to make it work =>

keditor/views/CKEditorView.php 44a45,48

// pull model data into area $defaultValue = $model->$attribute;

[b]Did I miss something?[/b]

I submit this as a patch on the ext, but I'm still too green around the ears.

Thanks in advance, Daniel

#3672 report it
Shahram at 2011/04/27 07:50am
@ddreggors

hi ddreggors,

the place is exactly in a view page. but before rendering the view, you should bind it with a model in your controller.

for example you some code like following in your controller:

$model = Pages::model()->findByPk(1);
$this->render('index', array(
'pages' => $model,
));

by this code, you will pass a model in the name of pages to your view/index file. I assumed that you have a field called content in your model which will be used in widget. If you want to use any other name, please edit your widget configuration.

Cheers

#3366 report it
David Dreggors at 2011/04/06 12:50pm
issues with this extension

I have the CKEditor extracted to my servers web root, and this extension extracted in my protected/extensions folder. Now if I use the code above I get the following Yii error:

Undefined variable: pages

and it has a reference to the code:

$this->widget('ext.ckeditor.CKEditorWidget',array(
   "model"=>$pages,                 # Data-Model <------- THIS LINE HIGHLIGHTED
   "attribute"=>'content',          # Attribute in the Data-Model
   "defaultValue"=>"Test Text",     # Optional
 
   # Additional Parameter (Check http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html)
   "config" => array(
       "height"=>"400px",
       "width"=>"100%",
       "toolbar"=>"Basic",
       ),

My question is, where are you supposed to place your code example above. In my attempt I placed your exact code in my index view on a new test site. Is a view the wrong place?

If this is supposed to be in a view, then what went wrong here?

#2545 report it
afunix at 2011/01/15 04:04pm
There is a bug in CKEditorView.php

Hmm. Patch is broken by parser. URL of patch: http://dl.dropbox.com/u/6312269/CKEditorView.php.patch

#2544 report it
afunix at 2011/01/15 04:02pm
There is a bug in CKEditorView.php

Hello. It's wrong to create attribute name as: get_class($model).'['.$attribute.']' It works wrong for complex forms with arrays as attributes. Yii way of doing that is: CHtml::resolveName($model, $attribute).

So the patch is:

--- CKEditorView.orig.php 2011-01-16 00:03:32.000000000 +0300 +++ CKEditorView.php 2011-01-16 00:05:02.000000000 +0300 @@ -33,7 +33,7 @@

require_once($ckEditor);

-$oCKeditor = new CKeditor(get_class($model).'['.$attribute.']'); +$oCKeditor = new CKeditor(CHtml::resolveName($model, $attribute)); $oCKeditor->basePath = $ckBasePath;

if(isset($config) && is_array($config)){ @@ -42,5 +42,5 @@ if(isset($config) && is_array($config)){ } }

-$oCKeditor->editor(get_class($model).'['.$attribute.']',$defaultValue); +$oCKeditor->editor(CHtml::resolveName($model, $attribute),$defaultValue); ?> \ No newline at end of file

#2443 report it
Shahram at 2011/01/03 01:37am
paulie:: Where to put ckeditor?

Hello Paulie,

I recommend to put the Ckeditor in your web-root (in your server it seems to be in www). If you put any code in your protected folder, it can be accessible only from Yii framework and you can not refer to it as an external code.

If you like to put your Ckeditor in any other folder (any where instead of protected folder) you can set the address using ckBasePath attribute.

#2241 report it
PaulDi at 2010/11/30 06:21pm
Where to put ckeditor?

Hi,

Could you advise where the ckeditor should be deployed to? The only way I can get this to work is to put ckeditor in "www" AND "www/protected". If I put ckeditor in just www or www/protected various include directives fail.

Thanks,

Paul.

Leave a comment

Please to leave your comment.

Create extension
Downloads