Yii中ckediter进一步配置

来源:互联网 发布:丁丁历险记 知乎 编辑:程序博客网 时间:2024/05/29 11:03

废话篇:由于本人没有安装录制桌面视频的软件,所以只能采用这种doc文档的方式。

Boylee呢已给大家在视频中讲了ckeditor的使用,非常感谢boylee 我连夜从yiiblog下载玩视频通宵看完。收获颇多。也是自己以后对自己复习ckeditor的使用有个文档依据写这个教程好了废话不多说了进入 正题。

  关于ckeditor 的工具栏是可以实现定制的。Yii 的扩展extension中的ckeditor的toolbar也是可以实现定制的。下面就从boylee 的视频结束讲解,视频下载可以从网站yiiblog中下载地址:http://yiiblog.info/blog/yii-go/ 下载视频教程3_5_3_extension_ckedit.mov还有editor扩展包CKediter- http://u.115.com/file/dnsrnmom

    当然网站内还有很多视频教程。希望大家多学习。再次感谢boylee ,     

下面如果您还不了解如何在yii中使用ckeditor 那么请认真的看一下boylee的视频教程。

在yii官方网站的extension 下载里面也能搜到ckeditor 但是没有下载文件包。

 

在yii 的extensions里面安装好并按照boylee的视频完成后。下面我们就要讲解一下 工具栏的自定义了。

 

找到 刚刚安装的extensions 里面editor/Ckkceditor.php文件。

你会发现变量$toolbarset已经声明;

而且如果你已经在你的Post页面安装了并调试好了ckeditor 你会发现和次代码非常类似

那么在你显示表单的页面你会看到和次断代码类似的代码

<?php $this->widget('application.extensions.editor.CKkceditor',array(                    "model"=>$model,                           "attribute"=>'content',         # Attribute in the Data-Model                     "height"=>'400px',                           "width"=>'100%',                           "filespath"=>Yii::app()->basePath."/../upload/",                    "filesurl"=>Yii::app()->baseUrl."/upload/",            ) ); ?> 


添加一条配置给$toolbar设置值 如下:

<?php $this->widget('application.extensions.editor.CKkceditor',array(                    "model"=>$model,                          "attribute"=>'content',         # Attribute in the Data-Model                    "height"=>'400px',                          "width"=>'100%',                          "toolbarSet"=>array(                              array( 'Source', '-', 'Bold','Italic', 'Underline', 'Strike' ),                               array( 'Image', 'Link','Unlink', 'Anchor' ) ),                                                                                                     "filespath"=>Yii::app()->basePath."/../upload/",                    "filesurl"=>Yii::app()->baseUrl."/upload/",            ) ); ?>


 

其中红色的部分就是我们要对ckeditor配置的自定义工具栏配置表单ckeditor 是按区域显示的所以 每个区域又是一个数组 同样也可以使用  '-'  这个分隔区域

 

然后 打开这个文件extensions 里面editor/Ckkceditor.php文件

 

我们要添加一些语句 找到如下语句:

$oCKeditor->basePath =$this->baseurl."/ckeditor/";    $oCKeditor->config['height'] =$this->height;    $oCKeditor->config['width'] =$this->width;if (isset($this->config) &&is_array($this->config))

修改成如下语句:

 

$oCKeditor->basePath =$this->baseurl."/ckeditor/";    $oCKeditor->config['height'] =$this->height;    $oCKeditor->config['width'] =$this->width;    // 判断$toolbarSet是否配置 如配置并将值赋值给$this->config[‘toolbar’];    if(isset($this->toolbarSet) &&is_array($this->toolbarSet))    {          $this->config['toolbar'] = $this->toolbarSet;    }    if (isset($this->config) &&is_array($this->config))    {      foreach ($this->config as$key=>$value)      {        $oCKeditor->config[$key] = $value;      }    }


添加了上面的蓝色的语句判断一下

这样配置在页面显示的工具如下

如需更多的配置选项请参考一下配置字段:

['Source','-','Save','NewPage','Preview','-','Templates'],
['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print','SpellChecker', 'Scayt'],
['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
['Form', 'Checkbox', 'Radio', 'TextField','Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
'/',
['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
['Link','Unlink','Anchor'],
['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
'/',
['Styles','Format','Font','FontSize'],
['TextColor','BGColor']
];

 

具体的字段呢 大家可以拿来试一下。Ok 写完了

=_= 困了 谁家了

By CodyHuny 2011-7-29 03:11


原创粉丝点击