CKEditor->代码点火器

发布于 2024-11-03 07:30:15 字数 9705 浏览 0 评论 0原文

我正在尝试配置 CKEditor,但我在源代码中得到以下内容,似乎助手没有从我的 index 函数 发送任何 $data,我的助手位于 application/ helpers

这是我的代码:

Helper:

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

/*
 * CKEditor helper for CodeIgniter
 * 
 * @author Samuel Sanchez <[email protected]> - 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> 

来源

<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">

查看

   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()

}

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 <[email protected]> - 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()

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

音栖息无 2024-11-10 07:30:15

你确实知道你可以将带有 JS 的 CK Editor 嵌入到文本区域,但对于这一切却没有太多了解。

http://ckeditor.com/demo

你到底怎么样.. 3 第二份工作。

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.

泅人 2024-11-10 07:30:15

一个问题可能是 JS 路径中的双斜杠;

CKEDITOR_BASEPATH = 'http://house.dev.local//';

另外,.htaccess 是否阻止访问您的 CKEditor 文件?

你的辅助函数在哪里?它有什么作用?
如果这是问题,请发布。
另外,您自己的助手不应该进入“系统/助手”,它们应该进入您的“应用程序/助手”,系统助手仅适用于核心助手。

One issue may be the double slash in your JS paths;

CKEDITOR_BASEPATH = 'http://house.dev.local//';

Also, is .htaccess blocking access to your CKEditor files ?

Where is your helper functions? what does it do ?
If that is the issue, please post it.
Also, your own helpers should NOT going in to 'system/helpers', they go in to your 'application/helpers', system helpers are for core helpers only.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文