【问题标题】:CKEditor won't load php variableCKEditor 不会加载 php 变量
【发布时间】:2013-05-05 06:46:59
【问题描述】:

我在我的 PHP 页面中添加了一个 textarea 控件,使用 CKEditor 的类。
现在如果 textarea 加载为空,CKEditor 就可以工作了。但是,如果我尝试在 textarea 中加载 PHP 变量,页面会正确显示编辑器,但不会显示内容(并且编辑器似乎被阻止)。 这是我的代码:

<div id="dialog-edit" title="Edit" style="display: none;">
    <table cellspacing="10">
        <tr>
            <td>
                <table>
                <form method="post" name="form">
                <tr>
                        <td>

                </td>
                <td>

                </td>
                <td>

                </td>
                </tr>
                </table>                    
                <br/>
                <textarea class="ckeditor" name="html" id="html" style="width: 766px; height: 390px; margin-left: 6px;"><?php echo htmlentities($html) ?></textarea><br/>
                <input type="submit" name="save" id="save" value="Salva modifiche" class="button" />
                </form>
            </td>
        </tr>
    </table>
</div>
<script type="text/javascript">
    function showDialogEdit()
    {
        $( "#dialog-edit" ).dialog({

                width: 680,
                height: 620,
                modal: true,
                open: function(event, ui)
                {

                }
            });
    }
</script>

textarea 必须将内容(作为 HTML 代码保存在 MySQL 数据库中)显示到 textarea 中,但它没有这样做。
是什么造成了这个问题?
谢谢。

【问题讨论】:

  • 你试过echo $html;而不是print $html;吗?你确定$html 的价值吗?
  • @Siamak.A.M 是的,但它仍然无法正常工作......
  • 没有更完整的代码示例,这是不可能的。请在jsfiddle.net 发布更多代码和/或创建功能示例
  • jsfiddle.net/mblase75/g2HFn/3 -- 仍然没有问题。但是,如果关注this example 有效,请告诉我——它使用 jQueryUI 对话框“打开”事件来触发没有“ckeditor”类的 CKEditor。
  • @FrancescoSorge 如果 Blazemonger 的回答解决了问题,请接受回答。它对所做的努力表示赞赏,并告诉正在搜索类似问题的人,您的问题得到了有用的答案。

标签: php html textarea ckeditor


【解决方案1】:

尝试按照 CKEditor 演示文件夹中的“代码替换”示例进行操作:

  1. 从文本区域中删除“ckeditor”类。
  2. 修改 jQueryUI 对话框“打开”事件以在对话框打开后触发它

http://jsfiddle.net/mblase75/g2HFn/4/

$("#dialog-edit").dialog({
    width: 680,
    height: 620,
    modal: true,
    open: function (event, ui) {
        CKEDITOR.replace('html');
    }
});

【讨论】:

    【解决方案2】:

    写入ckeditor的配置文件(config.js)

    CKEDITOR.editorConfig = function( config ) {
    
        /* ALLOW <?php ... ?> tags */
        config.protectedSource.push(/<\?[\s\S]*?\?>/g); 
        config.extraAllowedContent = 'style';
    };
    

    【讨论】:

      猜你喜欢
      • 2019-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-23
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多