2011-04-25 18 views
0

我想配置CKEditor的,但我得到了我的源代码如下,似乎助手并不会发送任何$数据从我指数函数,我的助手位于application/helpers的CKEditor - >笨

这是我的代码:

助手:

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

} 
+0

你需要在你的问题中提供更多的细节。你在这里指什么帮助者数组?你的意思是CI助手自动载入数组? – 2011-04-25 22:33:01

+0

完成我也完成了这个问题 – 2011-04-25 22:40:58

回答

2

你知道,你可以jst嵌入CK编辑器与JS到textarea,并没有太多与这一切。

http://ckeditor.com/demo

怎么样了,你到底如何。3第二份工作。

0

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

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

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

你的帮手功能在哪里?它有什么作用 ? 如果这是问题,请张贴它。 另外,你自己的助手不应该进入'系统/助手',他们会进入'应用程序/助手',系统助手只能用于核心助手。