CKEditor TypeError:c[a]在CodeIgniter中未定义


CKEditor TypeError: c[a] is undefined in CodeIgniter

我正试图在我的基于codeigniter的网站上安装CKEditor,我已经遵循了本教程:CodeigniterTutorial 中的CKEditor

但是我收到这个错误:TypeError: c[a] is undefined

CKEDITOR.lang.load/d()                   ckeditor___ckeditor:230
CKEDITOR.scriptLoader</<.load/f()        ckeditor___ckeditor:231
CKEDITOR.scriptLoader</<.load/x()        ckeditor___ckeditor:231
CKEDITOR.scriptLoader</<.load/A()        ckeditor___ckeditor:231
CKEDITOR.scriptLoader</<.load/u/g.$.onerror()

ckeditor文件夹所在的文件夹:assets/js/(将为:assets/js/ckeditor/)

CKEDITOR_BASEPATH是CKEDITOR_BASEPATH = 'http://localhost:5678/assets/js/ckeditor/';

我不知道这个错误是什么,我找不到正确的答案或修复它。

提前谢谢。

我也遇到了同样的问题。CKEditor无法正确识别自己的文件夹。因此,您应该在加载CKEDITOR之前设置一个CKEDITOR_BASEPATH变量。

这里简单地说:(但可能在其他地方解释得更好。)http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.html#.basePath

因此,实现方式如下:

<script>
  window.CKEDITOR_BASEPATH = 'http://example.com/path/to/libs/ckeditor/';
</script>

在我的情况下,我使用了window.CKEDITOR_BASEPATH = '/app/storereport/ckeditor/';

然后加载主ckeditor.js脚本。

<script type="application/javascript"/>
$(document).ready(function (){
    CKEDITOR.replace( 'product_content' );  // ID of element
});
</script>
  Use ckeditor in codeigniter    
  You need   
  1.Ckeditor helper : ckeditor_helper.php file put on system/helpers folder  
  2.Ckeditor-pacakge : http://ckeditor.com/download put on root directory 
 Write bellow code in controller file ex.Page.php      
-------------------------------------------------------------------------
 class Page extends CI_Controller {  
  public $data;   
  public function __construct() {  
        parent::__construct();  
         $this->load->helper('ckeditor');  //load helper
     }
  //load html view    
    public function add() {   
       $this->data['ckeditor'] = array(    
                'id' => 'format', //ID of the textarea that will be   replaced                'path' => '../ckeditor/',    
                    'config' => array(    
                    'toolbar' => "Full", //Using the Full toolbar   
                    'width' => "auto", //a custom width   
                    'height' => "300px", //a custom height   
                    ),   
                );    
                //Loading add File    
                $this->load->view('page/add', $this->data);    
            }    
    }     
load view file
--------------------------------------------------------------------- 
 add.php    
  <?php      
  $form_data = array('class'=>'form-horizontal', 'role'=>'form','id' => 'pagefrm','name' => 'pagefrm','enctype'=>'multipart/form-data');     
          echo form_open('Page/Newpage',$form_data);  ?>
   <div class="form-group">  
     <label class="col-md-3 control-label" for="example-email">Page Format </label>  
     <div class="col-md-6">
      <textarea class="form-control ckeditor"  name="format" id="format" ></textarea>
   </div>
    </div>
  <div class="form-group">
           <div class="col-sm-offset-5 col-sm-12">
                <button type="submit" class="btn btn-primary waves-effect waves-light">  Add </button>
           </div>
           </div>
<?php echo form_close();?>
write js to your view file->
<script src="<?php echo base_url();?>assets/js/jquery.min.js"></script>
<script src="<?php echo base_url();?>assets/js/jquery.validate.js"></script>
<script src="<?php echo base_url();?>ckeditor/ckeditor.js"></script> //manage your path
Here you also validate not allowed blank content not allowed using validate.js
--------------------------------------------------------------------
<script type="text/javascript">
    $(document).ready(function () {
        // When the browser is ready...
        $(function () {
            // form validation 
            $("#pagefrm").validate({
                // Specify the validation rules
                  rules: {
                     format: {
                        required: function (textarea) {
                            CKEDITOR.instances['format'].updateElement();
                            // update textarea
                            var editorcontent = textarea.value.replace(/<[^>]*>/gi, ''); // strip tags
                            return editorcontent.length === 0;
                        }
                    }
                },
                // Specify the validation error messages
                messages: {
                  format: "Please enter page format"
                },
                ignore: [],
                submitHandler: function (form) {
                    form.submit();
                }
            });
        });
    });
</script>

我在CI项目中也使用了Ckeditor。不要用这么长的路使用这些简单的步骤-

  1. 在您的路径assets/js/中导出您的Ckeditor库,因为您已经这样做了。

  2. 在你的html页面上包括这个-页面顶部的<script type="text/javascript" src="/assets/js/ckeditor/ckeditor.js"></script>

  3. 在html包含代码为-的脚本之后

    CKEDITOR.replace('content');

    /*content是要应用ckeditor的文本区域字段的名称*/

  //ckeditor_helper.php  
 //put on system/helpers/   
<?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>';
}