分享

brophp和ckeditor整合手记

 quasiceo 2014-04-26


来兄弟连快一个来月了,学习氛围杠杠的,教学环境也比想象中的要好,在完成每天课后作业之外,开始看brophp的源码,自己也用brophp框架动手做了一个小的应用,实现文章增加、删除、修改功能,在此过程中用到了一个富文本编辑的工具--ckeditor,经过一天时断时续的摸索,终于将该编辑器的PHP版本和brophp框架做了整合。
brophp目录结构
---------------
|
|-----bases
|  |
|  |--structure.class.php
|
|------classes
| |
|  |----ckeditor
|  |  |
|    |---ckeditor.class.php
|    |
|--commons
|
|--libs
|
|--brophp.php
步骤如下:

首先、将该编辑器的源文件夹整个拷贝到 brophp框架在的classes目录里边,修该其中ckeditor_php5.php文件名为ckeditor.class.php

其次、brophp.php添加如下
    ---->$GLOBALS["ckeditor_path"]=$GLOBALS["root"]."brophp/classes/ckeditor/"; //ckeditor根路径
|   ---->自动类加载函数: 添加ckeditor类自动加载功能
|      function __autoload($className){
|       if($className=="memcache"){        //如果是系统的Memcache类则不包含
|        return;
|       }else if($className=="Smarty"){    //如果类名是Smarty类,则直接包含
|        include "Smarty.class.php";
|       }else if($className=="Ckeditor"){
|        include "ckeditor/".strtolower($className).".class.php";//ckeditor类包含
|      
|       }else{                             //如果是其他类,将类名转为小写
|        include strtolower($className).".class.php";
|       }
|       Debug::addmsg("<b> $className </b>类", 1);  //在debug中显示自动包含的类
|      }
|
接下来修改、
structure.class.php------->这里边写入配置文件config.inc.php的字符串中添加如下ckeditor的默认配置项
|
|    /*************************
|    *ckeditor配置项
|    **************************
|    */
|    \$config= array(
|     'language' => 'zh-cn',
|     'skin' => 'kama',
|     'width' => 650,
|     'height' => 300,
|     'toolbar' => array(
|
|     array('Save', 'Source','-','NewPage','Preview','-','Templates' ),
|      array( 'Cut','Copy','Paste','PasteText','PasteFromWord','-', 'SpellChecker', 'Scayt' ),
|      array( 'Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'),
|      array('Form',
|      'Checkbox',
|      'Radio',
|      'TextField',
|      'Textarea',
|      'Select',
|      'Button',
|      'ImageButton',
|      'HiddenField'),
|      array( 'Bold','Italic','Underline','Strike','-','Subscript','Superscript'),
|      array( 'NumberedList','BulletedList','-','Outdent','Indent','Blockquote'),
|      array( 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'),
|      array( 'Image','Flash','Table','HorizontalRule','SpecialChar','MyPage','Maximize'),
|      array( 'TextColor','BGColor'),
|      array('Styles','Format','Font','FontSize')
|     ),
|    
|     'uiColor' => '#373737',
|     'font_names' => '宋体;楷体_GB2312;新宋体;黑体;隶书;幼圆;微软雅黑;Arial;'.
|     'Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana;',
|     'font_defaultLabel' => '宋体',
|     'fontSize_defaultLabel' => '19px',
|     'extraPlugins' => 'mypage',
|     );

最后说说、在控制器中调用方式:
  1、不用全局配置文件config.inc.php里边的默认配置
   $editor = new Ckeditor($GLOBALS["root"].'/brophp/classes/ckeditor/');
   $config = array();
   $config['uiColor'] = '#373737';
   $config['width'] = 500;
   $config['height'] = 100;
   $config['toolbar'] = array(
    array( 'Bold', 'Indent','Italic', 'Underline', 'Strike','Smiley' ),
    array( 'TextColor','Font','FontSize','RemoveFormat')
   );
  
   $editor->returnOutput = true;
   $code = $editor->editor("messsage", "留言内容",$config);
   $this->assign('ckeditor',$code);
  
  
  2、//声明使用全局配置文件config.inc.php里边的配置
   $editor = new Ckeditor($GLOBALS["ckeditor_path"]);
   global $config;//声明使用全局配置文件config.inc.php里边的配置
   $editor->returnOutput = true;  
   $code = $editor->editor("content",'',$config);
   $this->display('editor',$code)
  
  ----$code = $editor->editor("messsage", "留言内容",$config);
  
   editor方法的使用,其中有三个参数:
   第一个是,生成的textarea框的name值,可以通过此name值,使用$_GET[]和$_POST[]取到内容
   第二个参数是:默认内容,就是平时写到<textarea>留言内容</texarea>之间的内容,可为空字符串
   第三个参数是:富文本编辑器的菜单配置数组
《!---------------------------------------》
本来想上两张图的,不给上传。。。。。。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多