duanhe4155 2011-04-25 22:03
浏览 41
已采纳

CKEditor - > CodeIgniter

I am trying to configure CKEditor but I get the following in my source, it seems that the helper is not being sent any of the $data from my index function, My helper is located application/helpers

This is my code:

Helper:

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

/*
 * CKEditor helper for CodeIgniter
 * 
 * @author Samuel Sanchez <samuel.sanchez.work@gmail.com> - http://kromack.com/
 * @package CodeIgniter
 * @license http://creativecommons.org/licenses/by-nc-sa/3.0/us/
 * @tutorial http://kromack.com/developpement-php/codeigniter/ckeditor-helper-for-codeigniter/
 * @see http://codeigniter.com/forums/viewthread/127374/
 * @version 2010-08-28
 * 
 */

/**
 * This function adds once the CKEditor's config vars
 * @author Samuel Sanchez 
 * @access private
 * @param array $data (default: array())
 * @return string
 */
function cke_initialize($data = array()) {

    $return = '';

    if(!defined('CI_CKEDITOR_HELPER_LOADED')) {

        define('CI_CKEDITOR_HELPER_LOADED', TRUE);
        $return =  '<script type="text/javascript" src="'.base_url(). $data['path'] . '/ckeditor.js"></script>';
        $return .=  "<script type=\"text/javascript\">CKEDITOR_BASEPATH = '" . base_url() . $data['path'] . "/';</script>";
    } 

    return $return;

}

/**
 * This function create JavaScript instances of CKEditor
 * @author Samuel Sanchez 
 * @access private
 * @param array $data (default: array())
 * @return string
 */
function cke_create_instance($data = array()) {

    $return = "<script type=\"text/javascript\">
        CKEDITOR.replace('" . $data['id'] . "', {";

            //Adding config values
            if(isset($data['config'])) {
                foreach($data['config'] as $k=>$v) {

                    // Support for extra config parameters
                    if (is_array($v)) {
                        $return .= $k . " : [";
                        $return .= config_data($v);
                        $return .= "]";

                    }
                    else {
                        $return .= $k . " : '" . $v . "'";
                    }

                    if($k !== end(array_keys($data['config']))) {
                        $return .= ",";
                    }                       
                } 
            }               

    $return .= '});</script>';  

    return $return;

}

/**
 * This function displays an instance of CKEditor inside a view
 * @author Samuel Sanchez 
 * @access public
 * @param array $data (default: array())
 * @return string
 */
function display_ckeditor($data = array())
{
    // Initialization
    $return = cke_initialize($data);

    // Creating a Ckeditor instance
    $return .= cke_create_instance($data);


    // Adding styles values
    if(isset($data['styles'])) {

        $return .= "<script type=\"text/javascript\">CKEDITOR.addStylesSet( 'my_styles_" . $data['id'] . "', [";


        foreach($data['styles'] as $k=>$v) {

            $return .= "{ name : '" . $k . "', element : '" . $v['element'] . "', styles : { ";

            if(isset($v['styles'])) {
                foreach($v['styles'] as $k2=>$v2) {

                    $return .= "'" . $k2 . "' : '" . $v2 . "'";

                    if($k2 !== end(array_keys($v['styles']))) {
                         $return .= ",";
                    }
                } 
            } 

            $return .= '} }';

            if($k !== end(array_keys($data['styles']))) {
                $return .= ',';
            }           


        } 

        $return .= ']);';

        $return .= "CKEDITOR.instances['" . $data['id'] . "'].config.stylesCombo_stylesSet = 'my_styles_" . $data['id'] . "';
        </script>";     
    }   

    return $return;
}

/**
 * config_data function.
 * This function look for extra config data
 *
 * @author ronan
 * @link http://kromack.com/developpement-php/codeigniter/ckeditor-helper-for-codeigniter/comment-page-5/#comment-545
 * @access public
 * @param array $data. (default: array())
 * @return String
 */
function config_data($data = array())
{
    $return = '';
    foreach ($data as $key)
    {
        if (is_array($key)) {
            $return .= "[";
            foreach ($key as $string) {
                $return .= "'" . $string . "'";
                if ($string != end(array_values($key))) $return .= ",";
            }
            $return .= "]";
        }
        else {
            $return .= "'".$key."'";
        }
        if ($key != end(array_values($data))) $return .= ",";

    }
    return $return;
}
**.htaccess:**
# Customized error messages.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(index\.php|css|js|images|files|scripts|robots\.txt)
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule> 

Source

<script type="text/javascript" src="http://house.dev.local//ckeditor.js"></script><script type="text/javascript">CKEDITOR_BASEPATH = 'http://house.dev.local//';</script><script type="text/javascript">

View

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

class Editpage extends CI_Controller {

    function __construct(){
    parent::__construct();
    }

  function index($id){

        if(!$this->session->userdata('logged_in'))redirect('admin/home');

        $this->load->helper('ckeditor');
        //Ckeditor's configuration
        $this->data['ckeditor'] = array(

            //ID of the textarea that will be replaced
            'id'    =>  'content',
            'path'  => 'includes/js/ckedit',

            //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'
                    )
                )               
            )
        );
        if ($this->input->post('submit')){

            #The User has submitted updates, lets begin!

            #Set The validation Rules   
            $this->form_validation->set_rules('content', 'Content', 'trim|required|xss_clean');

            #if the form_validation rules fail then load the login page with the errors. Otherwise continue validating the user/pass
            if ($this->form_validation->run() == FALSE){

                $data['cms_pages'] = $this->navigation_model->getCMSPages($id);
                #connect to getCMSCotent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL.
                $data['page'] = $this->page_model->getCMSContent($id);

                $data['content'] = $this->load->view('admin/editpage', $data, TRUE);
                $this->load->view('admintemplate', $data);

            }               
            #Form Validation passed, so lets continue updating.
                #lets set some variables.
                $content = $this->input->post('content', TRUE);

                #Now if updatePage fails to update hte database then show "there was a problem", you could echo the db error itself
                if($this->page_model->updatePage($id, $content)) {
                    $data['cms_pages'] = $this->navigation_model->getCMSPages($id);
                    #connect to getCMSContent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL.
                    $data['page'] = $this->page_model->getCMSContent($id);
                    $data['success'] = TRUE;
                    $data['content'] = $this->load->view('admin/editpage', $data, TRUE);
                    $this->load->view('admintemplate', $data);
                }//END if updatePage
            }else{
            $data['cms_pages'] = $this->navigation_model->getCMSPages($id);

            #connect to getCMSCotent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL.
            $data['page'] = $this->page_model->getCMSContent($id);

            $data['content'] = $this->load->view('admin/editpage', $data, TRUE);
            $this->load->view('admintemplate', $data);
        }//END if post submitted
    } //END function index()

}
  • 写回答

2条回答 默认 最新

  • dt3358 2011-04-27 00:18
    关注

    You do know that you can jst embed CK Editor with JS to a textarea, and not much around with all this.

    http://ckeditor.com/demo

    Hows you exactly how.. 3 second job.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿