CKEditor PHP 集成

发布于 2024-09-16 10:04:30 字数 3079 浏览 3 评论 0原文

我正在使用 CKEditor 和 PHP。

使用示例 PHP,其中 $code 变量得到回显,打印触发 CKEditor 显示的代码。我只在真实的布局中执行相同的操作,结果是编辑器将其周围的 HTML 吞没,就好像它是它的初始值一样。

知道为什么我会收到这个吗?

这是代码:

// Include CKEditor class.
@require_once("ckeditor/ckeditor.php");

// Create class instance.
$CKEditor = new CKEditor();

// Do not print the code directly to the browser, return it instead
$CKEditor->returnOutput = true;

// Path to CKEditor directory, ideally instead of relative dir, use an absolute path:
//   $CKEditor->basePath = '/ckeditor/'
// If not set, CKEditor will try to detect the correct path.
$CKEditor->basePath = 'ckeditor/';

// Set global configuration (will be used by all instances of CKEditor).
$CKEditor->config['width'] = 600;

// Change default textarea attributes
//$CKEditor->textareaAttributes = array("cols" => 80, "rows" => 10);

//Set formatting options
$config['toolbar'] = array(
    array( 'Source','-',
          'NewPage','Preview','Templates','-',
          'Cut','Copy','Paste','PasteText','PasteFromWord','-',
          'Undo','Redo','-',
          'Find','Replace','-',
          'SelectAll','RemoveFormat','-',
          'Maximize', 'ShowBlocks'),
    '/',
    array('Bold','Italic','Underline','Strike','-',
          'Subscript','Superscript','-',
          'NumberedList','BulletedList','-',
          'Outdent','Indent','Blockquote','-',
          'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-',
          'Link','Unlink','Anchor','-',
          'Image','Flash','Table','HorizontalRule','SpecialChar'
          ),
    '/',
    array('Format','Font','FontSize','-',
          'TextColor','BGColor')
);

//Set skin
//$config['skin'] = 'kama';//kama si defailt skin for 3.4

//Set language and UI Color
$config['language']='ro';
//$config['uiColor']='#AADC6E';


//Remove the html tags in the status bar (e.g. body p strong for when cursor is in a strong tag within a p tag within the body)
$config['removePlugins']='elementspath';

//Allow / deny resizing of editor from dragging the bottom-right corner. Maximize will still work.
$config['removePlugins']='resize';//Remove resize image
$config['resize_enabled ']=false;//Disallow resizing

//Remove the collapse formatting area button (arrow on the middle-right part of the editor
//$config['toolbarCanCollapse']=false;

// The initial value to be displayed in the editor.
$initialValue = '';

//Add the CKFinder for upload of files directly from the `Add Image` / `Add Flash` buttons.
include_once($CKEditor->basePath.'ckfinder/ckfinder.php');
// You can use the "CKFinder" class to render CKFinder in a page:
$finder = new CKFinder();
$finder->BasePath = 'ckeditor/ckfinder/';   // The path for the installation of CKFinder (default = "/ckfinder/").
//$finder->SetupCKEditor($CKEditor,$CKEditor->basePath.'/ckfinder/');

// Create first instance.
$CKEditorOutput = $CKEditor->editor("continut",$initialValue,$config);

之后,我只需执行: $output.='

'.$CKEditorOutput.'
; 当然,CKEditor 所在的 div 周围的布局更大。

谢谢你!

I am using CKEditor with PHP.

Using the sample PHP where the $code variable gets echoed printing the code that triggers the CKEditor to show. I do the same only in a real layout and the what happens is the Editor engulfs the surroding HTML inside it as if it was the initialValue for it.

Any idea why I am getting this, please?

Here is the code:

// Include CKEditor class.
@require_once("ckeditor/ckeditor.php");

// Create class instance.
$CKEditor = new CKEditor();

// Do not print the code directly to the browser, return it instead
$CKEditor->returnOutput = true;

// Path to CKEditor directory, ideally instead of relative dir, use an absolute path:
//   $CKEditor->basePath = '/ckeditor/'
// If not set, CKEditor will try to detect the correct path.
$CKEditor->basePath = 'ckeditor/';

// Set global configuration (will be used by all instances of CKEditor).
$CKEditor->config['width'] = 600;

// Change default textarea attributes
//$CKEditor->textareaAttributes = array("cols" => 80, "rows" => 10);

//Set formatting options
$config['toolbar'] = array(
    array( 'Source','-',
          'NewPage','Preview','Templates','-',
          'Cut','Copy','Paste','PasteText','PasteFromWord','-',
          'Undo','Redo','-',
          'Find','Replace','-',
          'SelectAll','RemoveFormat','-',
          'Maximize', 'ShowBlocks'),
    '/',
    array('Bold','Italic','Underline','Strike','-',
          'Subscript','Superscript','-',
          'NumberedList','BulletedList','-',
          'Outdent','Indent','Blockquote','-',
          'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-',
          'Link','Unlink','Anchor','-',
          'Image','Flash','Table','HorizontalRule','SpecialChar'
          ),
    '/',
    array('Format','Font','FontSize','-',
          'TextColor','BGColor')
);

//Set skin
//$config['skin'] = 'kama';//kama si defailt skin for 3.4

//Set language and UI Color
$config['language']='ro';
//$config['uiColor']='#AADC6E';


//Remove the html tags in the status bar (e.g. body p strong for when cursor is in a strong tag within a p tag within the body)
$config['removePlugins']='elementspath';

//Allow / deny resizing of editor from dragging the bottom-right corner. Maximize will still work.
$config['removePlugins']='resize';//Remove resize image
$config['resize_enabled ']=false;//Disallow resizing

//Remove the collapse formatting area button (arrow on the middle-right part of the editor
//$config['toolbarCanCollapse']=false;

// The initial value to be displayed in the editor.
$initialValue = '';

//Add the CKFinder for upload of files directly from the `Add Image` / `Add Flash` buttons.
include_once($CKEditor->basePath.'ckfinder/ckfinder.php');
// You can use the "CKFinder" class to render CKFinder in a page:
$finder = new CKFinder();
$finder->BasePath = 'ckeditor/ckfinder/';   // The path for the installation of CKFinder (default = "/ckfinder/").
//$finder->SetupCKEditor($CKEditor,$CKEditor->basePath.'/ckfinder/');

// Create first instance.
$CKEditorOutput = $CKEditor->editor("continut",$initialValue,$config);

Afterwards, I just do: $output.='<div>'.$CKEditorOutput.'</div>;
Of course, the layout around the div in which the CKEditor resides is larger.

Thank you!

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

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

发布评论

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

评论(1

笑看君怀她人 2024-09-23 10:04:30

啊,明白了...

这一行: $CKEditorOutput = $CKEditor->editor("continut",$initialValue,$config);

布局包含一个 ID 选择器为“continut”的 div ”,所以

因此,一切都变得混乱,并将该 div 和所有内部 HTML 转换为 RTE Textarea。

抱歉并感谢大家!

Ah, got it...

This line: $CKEditorOutput = $CKEditor->editor("continut",$initialValue,$config);

The layout contains a div with an ID selector of "continut", so <div id="continut">. Thus messing everything up and turning that div and all inner HTML into the RTE Textarea.

Sorry and thanks everyone!

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