blueguy
(Okamismo)
September 29, 2011, 4:03pm
#1
Hola espero me puedan ayudar, integre el ckeditor al yii pero deseo personalizar la barra de herramientas y observe que tiene tres opciones como basic, full, advance en la advance no me muestra nada y me gustaria saber como hacer para yo poder personalizarlo.
Gracias!!!
Lindo dia!!!
Hi blueguy,
Here is a little widget I started. Nothing big. Here is how I have it setup:
/protected/components/WCKeditor.php
/protected/components/WCKeditor/config.js <- my own custom config for CKEditor
/protected/components/WCKeditor/ckeditor <- CKEditor downloaded from the official site.
/protected/components/WCKeditor/ckeditor/ <- You should end up with CKeditor’s files here (example: ckeditor.js).
In your view with the form:
<?php $this->widget('WCKeditor', array( 'model' => $model, 'attribute' => 'body',)); ?>
WCKEditor.php (CInputWidget):
<?php
class WCKeditor extends CInputWidget
{
/**
* @var string Path to the WCKEditor assets folder.
*/
public $assetDir;
/**
* @var string Absolute URL of the published assets folder.
*/
public $publishUrl;
/**
* @var boolean Use the CKeditor's jQuery adapter
*/
public $usejQuery = TRUE;
/**
* Initialize the Widget
*/
public function init() {
parent::init();
$this->assetDir = $this->assetDir ? $this->assetDir : dirname(__FILE__) . '/WCKeditor';
$this->publishUrl = Yii::app()->getAssetManager()->publish($this->assetDir);
}
/**
* Run the widget
*/
public function run() {
list($name, $id) = $this->resolveNameID();
if ( isset($this->htmlOptions['id']) ) $id = $this->htmlOptions['id'];
else $this->htmlOptions['id'] = $id;
if ( isset($this->htmlOptions['name']) ) $name = $this->htmlOptions['name'];
/* @var $cs CClientScript */
$cs = Yii::app()->clientScript;
$cs->registerScriptFile($this->publishUrl . '/ckeditor/ckeditor.js', CClientScript::POS_END);
if ( $this->usejQuery ) {
$cs->registerScriptFile($this->publishUrl . '/ckeditor/adapters/jquery.js', CClientScript::POS_END);
$script .= '$(\'#'. $id .'\').ckeditor({customConfig: \''. $this->publishUrl .'/config.js\'});';
}
else {
$script .= 'CKEDITOR.replace(\''. $id .'\', {customConfig: \''. $this->publishUrl .'/config.js\'});';
}
$cs->registerScript('WCKEditor_'. $id, $script, CClientScript::POS_LOAD);
if ( $this->hasModel() ) echo CHtml::activeTextArea($this->model, $this->attribute, $this->htmlOptions);
else echo CHtml::textArea($name, $this->value, $this->htmlOptions);
}
}