• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

关于YII视图整合kindeditor如何扩展的方法

php 搞代码 3年前 (2022-01-22) 14次浏览 已收录 0个评论

这篇文章主要介绍了YII视图整合kindeditor扩展的方法,较为详细的分析了Yii框架整合kindeditor的功能实现代码与设置相关技巧,需要的朋友可以参考下

本文实例讲述了YII视图整合kindeditor扩展的方法。分享给大家供大家参考,具体如下:

比较喜欢用kindeditor,YII上的版本比较旧,所以自己重新整了个扩展
先在protected\extensions下创建KEditor文件夹用来放文件,keSource里放kindeditor的源文件,然后建三个类KEditor、KEditorManage和KEditorUpload,KEditor是扩展的主文件,KEditorManage是用来浏览服务器文件的,KEditorUpload是用来示例接收上传文件的,

KEditor代码

<?phpclass KEditor extends CWidget{  /*   * TEXTAREA输入框的属性,保证js调用KE失败时,文本框的样式。   */  public $textareaOptions=array();  /*   * 编辑器属性集。   */  public $properties=array();  /*   * TEXTAREA输入框的name,必须设置。   * 数据类型:String   */  public $name;  /*   * TEXTAREA的id,可为空   */  public $id;  public $model;  public $baseUrl;  public static function getUploadPath(){    $dir = dirname(__FILE__).DIRECTORY_SEPARATOR.'keSource';    if(isset(Yii::app()->params->uploadPath)){      return Yii::getPathOfAlias('webroot').str_replace(                '/',DIRECTORY_SEPARATOR,                Yii::app()->params->                uploadPath);    }    return Yii::app()->getAssetmanager()        ->getPublishedPath($dir).DIRECTORY_SEPARATOR.'upload';  }  public static function getUploadUrl(){    $dir = dirname(__FILE__).DIRECTORY_SEPARATOR.'keSource';    if(isset(Yii::app()->params->uploadPath)){      return Yii::app()->baseUrl.Yii::app()->params->uploadPath;    }    return Yii::app()->getAssetManager()->publish($dir).'/upload';  }  public function init(){    if($this->name===null)      throw new CException(Yii::t('zii','The id property cannot be empty.'));    $dir = dirname(__FILE__).DIRECTORY_SEPARATOR.'keSource';    $this->baseUrl<p>4本文¥来源gao!%daima.com搞$代*!码$网9</p><pre>搞代gaodaima码

=Yii::app()->getAssetManager()->publish($dir); $cs=Yii::app()->getClientScript(); $cs->registerCssFile($this->baseUrl.'/themes/default/default.css'); if(YII_DEBUG) $cs->registerScriptFile($this->baseUrl.'/kindeditor.js'); else $cs->registerScriptFile($this->baseUrl.'/kindeditor-min.js'); } public function run(){ $cs=Yii::app()->getClientScript(); $textAreaOptions=$this->gettextareaOptions(); $textAreaOptions['name']=CHtml::resolveName($this->model,$this->name); $this->id=$textAreaOptions['id']=CHtml::getIdByName($textAreaOptions['name']); echo CHtml::activeTextArea($this->model,$this->name,$textAreaOptions); $properties_string = CJavaScript::encode($this->getKeProperties()); $js=<<<EOFKindEditor.ready(function(K) { var editor_$this->id = K.create('#$this->id',$properties_string );});EOF; $cs->registerScript('KE'.$this->name,$js,CClientScript::POS_HEAD); } public function gettextareaOptions(){ //允许获取的属性 $allowParams=array('rows','cols','style'); //准备返回的属性数组 $params=array(); foreach($allowParams as $key){ if(isset($this->textareaOptions[$key])) $params[$key]=$this->textareaOptions[$key]; } $params['name']=$params['id']=$this->name; return $params; } public function getKeProperties(){ $properties_key=array( 'width', 'height', 'minWidth', 'minHeight', 'items', 'noDisableItems', 'filterMode', 'htmlTags', 'wellFormatMode', 'resizeType', 'themeType', 'langType', 'designMode', 'fullscreenMode', 'basePath', 'themesPath', 'pluginsPath', 'langPath', 'minChangeSize', 'urlType', 'newlineTag', 'pasteType', 'dialogAlignType', 'shadowMode', 'useContextmenu', 'syncType', 'indentChar', 'cssPath', 'cssData', 'bodyClass', 'colorTable', 'afterCreate', 'afterChange', 'afterTab', 'afterFocus', 'afterBlur', 'afterUpload', 'uploadJson', 'fileManagerJson', 'allowPreviewEmoticons', 'allowImageUpload', 'allowFlashUpload', 'allowMediaUpload', 'allowFileUpload', 'allowFileManager', 'fontSizeTable', 'imageTabIndex', 'formatUploadUrl', 'fullscreenShortcut', 'extraFileUploadParams', ); //准备返回的属性数组 $params=array(); foreach($properties_key as $key){ if(isset($this->properties[$key])) $params[$key]=$this->properties[$key]; } return $params; }}


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:关于YII视图整合kindeditor如何扩展的方法
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址