CI框架中集成CKEditor编辑器的教程

CKEditor是在很多开发过程中都会用到的一个富文本编辑器,那么如何在CI框架中使用它呢?这里介绍了在CI下使用CKEditor的方法,版本比较低,是在CI 1.7.3下使用fckeditor 2.6.6。供大家参考。

1、将fckeditor目录置入CI_PATH/system/plugins/

2、在CI_PATH/system/application/config/config.php中加入:

$config[‘fckeditor_basepath‘] = "/system/plugins/fckeditor/"; 
$config[‘fckeditor_toolbarset_default‘] = ‘Default‘;

3、创建helper,在/system/application/helpers新建form_helper.php

复制代码代码如下:

<?php 
if (!defined(‘BASEPATH‘)) exit(‘No direct script access allowed‘);
include_once( BASEPATH . ‘/helpers/form_helper‘.EXT);
function form_fckeditor($data = ‘‘, $value = ‘‘, $extra = ‘‘)
{
     $CI =& get_instance();
    $fckeditor_basepath = $CI->config->item(‘fckeditor_basepath‘);
     require_once( $_SERVER["DOCUMENT_ROOT"] . $fckeditor_basepath. ‘fckeditor.php‘ );
    $instanceName = ( is_array($data) && isset($data[‘name‘])   ) ? $data[‘name‘] : $data;
    $fckeditor = new FCKeditor($instanceName);
     if( $fckeditor->IsCompatible() )
    {
         $fckeditor->Value = html_entity_decode($value);
        $fckeditor->BasePath = $fckeditor_basepath;
         if( $fckeditor_toolbarset = $CI->config->item(‘fckeditor_toolbarset_default‘))
                $fckeditor->ToolbarSet = $fckeditor_toolbarset;
         if( is_array($data) )
        {
            if( isset($data[‘value‘]) )
                $fckeditor->Value = html_entity_decode($data[‘value‘]);
             if( isset($data[‘basepath‘]) )
                $fckeditor->BasePath = $data[‘basepath‘];
             if( isset($data[‘toolbarset‘]) )
                $fckeditor->ToolbarSet = $data[‘toolbarset‘];
             if( isset($data[‘width‘]) )
                $fckeditor->Width = $data[‘width‘];
             if( isset($data[‘height‘]) )
                $fckeditor->Height = $data[‘height‘];
        }
        return $fckeditor->CreateHtml();
    }
    else
    {
        return form_textarea( $data, $value, $extra );
    }
}
?>

4、在项目中使用fckeditor

复制代码代码如下:

<?php
$this->load->helper(‘form_helper‘);
$data = array(
    ‘name‘        => ‘newsContent‘,
    ‘id‘          => ‘newsContent‘,
    //‘toolbarset‘  => ‘Advanced‘,
    ‘basepath‘    => $this->config->item(‘fckeditor_basepath‘),
    ‘width‘       => ‘80%‘,
    ‘height‘      => ‘200‘
);
echo form_fckeditor( $data );
?>

时间: 2024-08-01 09:30:34

CI框架中集成CKEditor编辑器的教程的相关文章

细说shiro之五:在spring框架中集成shiro

官网:https://shiro.apache.org/ 1. 下载在Maven项目中的依赖配置如下: <!-- shiro配置 --> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <version>${version.shiro}</version> </dependency&g

CI框架中的SQL注入隐患

 0x00 在CI框架中,获取get和post参数是使用了$this->input类中的get和post方法. 其中,如果get和post方法的第二个参数为true,则对输入的参数进行XSS过滤,注意只是XSS过滤,并不会对SQL注入进行有效的防范. 例子: Controller中,定义一个shit方法,获取get数据: 指定了第二个参数为true: (1)XSS测试 (2)SQL注入测试 并不会对单引号进行处理. 例子在程式舞曲CMS中,该CMS是基于CI框架进行开发的CMS: 这里的变量

CI框架中 类名不能以方法名相同

昨天晚上一个坑爹的问题折腾了我一晚上,首先我来说下我的代码,我建立了一个index的控制器然后呢  在控制器里有一个index的方法.页面模板都有. if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Index extends CI_Controller{ public function index(){ $this->load->view('index.html'); } } 然后你在浏览器中

将smarty模版引擎整合到CI框架中

将smarty模版引擎整合到CI框架中. 下载:ci,smarty 配署ci 在这里就不多说了…… 1.  将下载好的smarty包的lib文件上传到ci中的application/libraries 文件中,将取名称修改为smarty,在libraries文件新建cismarty.php文件,内容如下: if (!defined('BASEPATH')) exit("no direct script access allowd"); //以下是加载smarty的类文件 require

在YII2框架中使用UEditor编辑器发布文章

在YII2框架中使用UEditor编辑器发布文章 创建文章数据表 文章数据表主要有4个字段 id  主键(int) title 标题(varchar) content 内容(text) created_time 创建时间(int) 创建文章模型 创建文章模型,不要忘记设置验证规则和字段的名称 namespace backend\models; class Article extends \yii\db\ActiveRecord { public function rules() { return

php CI框架中base_url 和site_url的区别

在CI框架中base_url得到的路径是不包括入口的文件index.php文件 site_url包含了入口文件.当调用MVC模式的时候使用site_url  加载页面 <link href="<?php echo base_url('assets/styles/main.css');?>" rel="stylesheet" type="text/css" /> <form method="post"

对CI框架中几个文件libraries

对CI框架中几个文件libraries,helpers,hooks夹说明 来源:未知    时间:2014-10-20 11:37   阅读数:117   作者:xbdadmin [导读] 1.library文件夹 如果你想扩展CI的功能,那么就把你的类库放在这,注意,这个文件夹是有class组成的,可以看看如果 加载library注意事项 ! 2.helper文件夹 如果你需要使用一些函数来帮你... 1.library文件夹 如果你想扩展CI的功能,那么就把你的类库放在这,注意,这个文件夹是

springboot框架中集成thymeleaf引擎,使用form表单提交数据,debug结果后台获取不到数据

springboot框架中集成thymeleaf引擎,使用form表单提交数据,debug结果后台获取不到数据 表单html: <form class="form-horizontal form-material" th:object="${user}" th:action="@{/user/updateOneUserInfo}" method="post"> <input type="hidden

CI框架中自定义view文件夹位置

要想自定义view文件夹的位置,首先要了解CI框架时如何加载view文件夹的. CI中默认调用view的方法是: $this->load->view(); //这一行代码的原理是什么呢?请往下看: 我们打开application/core/Loader.php,里面有一个这样的方法: public function add_package_path($path, $view_cascade = TRUE) { $path = rtrim($path, '/').'/'; array_unshi