`
天梯梦
  • 浏览: 13731229 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

CKEditor Helper for CodeIgniter

阅读更多

Using CKEditor as a plugin in your CodeIgniter applications

CKEditor is a powerfull WYSIWYG text editor licensed under the GPL, LGPL and MPL open source licenses. CKEditor can easilly be added to any web page, you will find below a simple way to integrate CKeditor to your CodeIgniter applications .

 

Downloading CKEditor

The first step is to download the CKEditor editor package , note that the helper have only be tested over CKEditor 3.0.2. Once done, you should consider to remove the _samples and _sources directories from the uncompressed files.

Then, place the entire ckeditor directory into a /js/ folder. You can place it anywhere but remember to set the correct path when initializing the helper.

Adding the CKEditor helper for CodeIgniter

Download and place the ckeditor_helper.php file into the CodeIgniter’s system/application/helpers folder.

This helper can, for the moment, manage all CKEditor’s available configuration options and custom styles definitions .

Creating the controller

First of all, we are going to create a controller that will set all the helper’s configuration options. You are able to set all CKEditor’s available configuration options inside the config array. We are also going to define two custom styles to replace the CKEditor’s default styles. Note that the id must match the textarea’s id in the view.

 

<?php
class Ckeditor extends Controller {
	public $data 	= 	array();
	public function __construct() {
		parent::Controller();
		$this->load->helper('url'); //You should autoload this one ;)
		$this->load->helper('ckeditor');
		//Ckeditor's configuration
		$this->data['ckeditor'] = array(
			//ID of the textarea that will be replaced
			'id' 	=> 	'content', 	// Must match the textarea's id
			'path'	=>	'js/ckeditor',	// Path to the ckeditor folder relative to index.php
			//Optionnal values
			'config' => array(
				'toolbar' 	=> 	"Full", 	//Using the Full toolbar
				'width' 	=> 	"550px",	//Setting a custom width
				'height' 	=> 	'100px',	//Setting a custom height
			),
			//Replacing styles from the "Styles tool"
			'styles' => array(
				//Creating a new style named "style 1"
				'style 1' => array (
					'name' 		=> 	'Blue Title',
					'element' 	=> 	'h2',
					'styles' => array(
						'color' 		=> 	'Blue',
						'font-weight' 		=> 	'bold'
					)
				),
				//Creating a new style named "style 2"
				'style 2' => array (
					'name' 		=> 	'Red Title',
					'element' 	=> 	'h2',
					'styles' => array(
						'color' 		=> 	'Red',
						'font-weight' 		=> 	'bold',
						'text-decoration'	=> 	'underline'
					)
				)
			)
		);
	}
	public function index() {
		$this->load->view('ckeditor', $this->data);
	}
}
 

Creating the view

The ckeditor.php view only has to display a textarea element with the matched id and call the display_ckeditor() helper’s function.

 

<textarea name="content" id="content" ><p>Example data</p></textarea>
<?php echo display_ckeditor($ckeditor); ?>
 

That’s all ! If you’ve followed all the steps correctly, CKEditor should shows up in the view. Please note that I assume that you are loading also a correct header and footer view with all the xHTML required stuff.

Downloading the tutorial

Source files of this tutorial (controller, helper, and view) can be downloaded here .

 

 

 

第二种方法:

 

Minimized version:

ckeditor_helper.php

 

<?php
    if(!defined('BASEPATH')) exit('No direct script access allowed');

    function form_ckeditor($data)
    {
        return  < script type="text/javascript" src="'.base_url().'application/plugins/ckeditor/ckeditor.js"></script>' .
         '<script type="text/javascript">CKEDITOR.replace("'.$data['id'].'");</script>';
    }
 

To use:

 

    echo form_ckeditor(array('id'=>'textarea_id'));
 

 

With many parameters and personalized thinks...
ckeditor_helper.php

 

<?php
    if(!defined('BASEPATH')) exit('No direct script access allowed');

    function form_ckeditor($data)
    {
        $data['language'] = isset($data['language']) ? $data['language'] : 'es';
       
        $size    = isset($data['width']) ? 'width: "'.$data['width'].'", ' : '';
        $size  .= isset($data['height']) ? 'height: "'.$data['height'].'", ' : '';
       
        $options = '{'.
                $size.
                'language: "'.$data['language'].'",
               
                stylesCombo_stylesSet: "my_styles",
               
                startupOutlineBlocks: true,
                entities: false,
                entities_latin: false,
                entities_greek: false,
                forcePasteAsPlainText: false,
               
                filebrowserImageUploadUrl : "filexplorers/fckeditor_upload/image", // << My own file uploader
                filebrowserImageBrowseUrl : "filexplorers/inlinebrowse/image", // << My own file browser
                filebrowserImageWindowWidth : "80%",
                filebrowserImageWindowHeight : "80%",   

               
                toolbar :[
                    ["Source","-","FitWindow","ShowBlocks","-","Preview"],
                    ["Undo","Redo","-","Find","Replace","-","SelectAll","RemoveFormat"],
                    ["Cut","Copy","Paste","PasteText","PasteWord","-","Print","SpellCheck"],
                    ["Form","Checkbox","Radio","TextField","Textarea","Select","Button","ImageButton","HiddenField"],
                    ["About"],
                       
                    "/",
                   
                    ["Bold","Italic","Underline"],
                    ["OrderedList","UnorderedList","-","Blockquote","CreateDiv"],
                   
                    ["Image","Flash","Table"],
                   
                    ["Link","Unlink","Anchor"],
                    ["Rule","SpecialChar"],
                    ["Styles"]
                ]
            }';
       
       
        $my_styles = 'CKEDITOR.addStylesSet("my_styles",
            [
                // Block Styles
                { name : "H3", element : "h3"},
                { name : "Heading 4", element : "h4"},
                { name : "Heading 5", element : "h5"},
                { name : "Heading 6", element : "h6"},
                { name : "Document Block", element : "div"},
                { name : "Preformatted Text", element : "pre"},
                { name : "Address", element : "address"},
           
                // Inline Styles
                { name: "Centered paragraph", element: "p", attributes: { "class": "center" } },
               
                { name: "IMG bordered", element: "img", attributes: { "class": "bordered" } },
               
                { name: "IMG left", element: "img", attributes: { "class": "left" } },
                { name: "IMG right", element: "img", attributes: { "class": "right" } },
               
                { name: "IMG left bordered", element: "img", attributes: { "class": "left bordered" } },
                { name: "IMGright bordered", element: "img", attributes: { "class": "right bordered" } },
            ]);';
       
        return
        // fix: move to <HEAD...
        '<script type="text/javascript" src="'.base_url().'application/plugins/ckeditor/ckeditor.js"></script>' .

        // put the CKEditor
         '<script type="text/javascript">' .
                $my_styles .
                'CKEDITOR.replace("'.$data['id'].'", ' . $options . ');</script>';
    }
 

To use:

 

    echo form_ckeditor(array(
                'id'         =>  'textarea_id',
                'width'   => '500',
                'height'  => '300',
                'value'   => htmlentities($textarea_value)
            ));
 

 

 

Look at CodeIgniter forum: <!-- m -->http://codeigniter.com/forums/viewthread/127374/ <!-- m -->

 

 

分享到:
评论

相关推荐

    CKeditor for JAVA v3.6.4

    CKeditor for JAVA v3.6.4是一款专为JAVA开发者设计的在线网页编辑器,它提供了丰富的文本编辑功能,使得用户可以在浏览器环境下实现所见即所得(WYSIWYG)的编辑体验。这款编辑器不仅限于JAVA平台,还兼容多种...

    CKEditor for Zen Cart v1.xx

    "CKEditor for Zen Cart v1.xx" 是专门为Zen Cart电子商务系统定制的一个版本,确保了与Zen Cart的无缝集成和兼容性。 Zen Cart是一款开源的在线商店管理系统,基于PHP语言和MySQL数据库,它为商家提供了一个功能...

    CKEditor3.6.2 for java

    在本资源"CKEditor3.6.2 for java"中,重点是将CKEditor与Java环境集成,特别是针对Eclipse开发环境的配置。以下是关于这个主题的详细知识点: 1. **CKEditor 3.6.2**: 这是CKEditor的一个特定版本,发布于2010年,...

    在线文本编辑器ckeditor3.6.2 for JAVA

    CKEditor 3.6.2 for Java版主要包含以下组件: 1. WAR包:WAR(Web Application Archive)是Java Web应用程序的标准打包格式,可以直接部署在支持Servlet容器(如Tomcat、Jetty)上。这个WAR文件包含了完整的...

    CKeditor for ASP.NET

    在"CKeditor for ASP.NET"的项目中,提供的文件包含以下关键知识点: 1. **LICENSE.html**:此文件通常包含了软件的许可协议,详细规定了用户如何合法地使用、修改和分发CKeditor的源代码。对于开发者来说,理解...

    CKEditor3.6.4+CKFinder2.3 for java破解整合

    CKEditor3.6.4+CKFinder2.3 for java破解整合

    CKEditor for ASP.NET

    是一个专门使用在网页上属于开放源代码的所见即所得文字编辑器。它志于轻量化,不需要太复杂的安装步骤即可使用。...“FCKeditor”名称中的“FCK” 是这个编辑器的作者的名字Frederico Caldeira Knabben的缩写。

    CKEditor3.53_Finder_for_java2.1整合所有文件

    Finder for java2.1可能是与CKEditor集成的一个工具或库,用于帮助开发者更方便地在Java环境中管理和使用CKEditor。 在Java Web开发中,CKEditor通常通过JavaScript在客户端运行,而服务器端则处理CKEditor提交的富...

    CKeditor for joomla1.7 v3.6.2.rar

    CKeditor是一款在线网页编辑插件(用浏览器编辑后所见即所得),支持多种平台下的脚本(asp aspx php cfm Dhtml htc),还集成了上传图片组件,含简、繁中文 CKeditor for joomla1.7兼容JOOMLA!1.5以上。 易于安装和...

    asp.net 使用ckeditor5富文本编辑器包含图片上传全部代码

    在ASP.NET应用中,CKEditor5是一款常用的富文本编辑器,它提供了丰富的文本格式化功能,包括图片上传。本文将详细介绍如何在ASP.NET环境中集成CKEditor5并实现图片上传功能。 首先,我们需要在项目中引入CKEditor5...

    codeigniter-ckeditor-kcfinder:with带有CKEDITOR和KCFINDER的Codeigniter

    带Ckeditor和KCFinder的Codeigniter 3 与和使用会话authenctication 设置 下载, , 主文件 认沽 , 你文件。 例如,我创建资产目录。 配置1 在根目录上打开index.php CI文件并修改一些行 $application_folder = '...

    ckeditor for java 上传图片功能

    CKEditor 是一个流行的富文本编辑器,广泛应用于Web开发中,提供丰富的文本格式化和多媒体插入功能。在Java环境中,CKEditor 可以被集成到Web应用中,以支持用户在网页上编辑内容,比如发布文章或填充表单。本文将...

    ckeditor for java 模板项目

    **ckeditor for java 模板项目** CKEditor是一款流行的富文本编辑器,广泛应用于网页和应用程序中,提供丰富的文本格式化和编辑功能。在Java环境中,CKEditor可以通过与Servlet或JSP页面结合,使得用户能够在服务器...

    CKeditor for ASP.NET 3.6.2

    这个开源的HTML文本编辑器可以让Web程序拥有如MS Word这样强大的编辑功能. FCKeditor支持当前流行的浏览器如IE,Firefox,Netscape,Opera等. 在线网页编辑插件(用浏览器编辑后所见即所得),支持多种平台下的脚本(asp ...

    ckeditor4 for .net完整解决方案代码,带图片上传

    CKEditor4是一款流行的富文本编辑器,广泛应用于Web开发中,提供丰富的文本格式化功能,如插入图片、链接、表格等。在.NET框架下,CKEditor4可以与ASP.NET结合,实现用户友好的内容编辑界面。这个压缩包提供的是一套...

    CKeditor for Drupal 7 v3.6.3.zip

    CKeditor是一款在线网页编辑插件(用浏览器编辑后所见即所得),支持多种平台下的脚本(asp aspx php cfm Dhtml htc),还集成了上传图片组件,含简、繁中文   ...CKeditor for Drupal 7兼容Drupal 7。

    ckeditor 带上传例子 for java jsp

    在这个“ckeditor带上传例子 for java jsp”的压缩包中,包含了一个基于Java和JSP的CKEditor上传功能示例。 首先,我们需要理解CKEditor的上传功能。在CKEditor中,用户可以插入图片、文件或其他媒体内容,而上传...

    CKEditor for Java Integration Guide

    CKEditor for Java Integration Guide 在 jsp 中通过自定义标签调用

    asp.net CKEditor 4.0和CKFinder 2.1的应用_网页编辑器

    CKEditor 4.0这是 CKEditor 一个非常好的、稳定的版本,与CKFinder(已破解)实现了图片上传等功能,并且还对文本显示问题进行了编辑,个人觉得很好用,给大家分享下吧。大家也可以进行自己的修改。例如 BiDi 支持、...

Global site tag (gtag.js) - Google Analytics