brophp和ckeditor整合手记

来兄弟连快一个来月了,学习氛围杠杠的,教学环境也比想象中的要好,在完成每天课后作业之外,开始看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>之间的内容,可为空字符串
第三个参数是:富文本编辑器的菜单配置数组
《!---------------------------------------》
原文地址: http://bbs.lampbrother.net/read-htm-tid-118618.html
<script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/buttonLite.js#style=-1&uuid=&pophcol=3&lang=zh"></script> <script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/bshareC0.js"></script>
阅读(85) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值