1
0

More than 1 year has passed since last update.

ダイアログ内でCLEditorが使えないときの対処法

Posted at

(そもそも)CLEditorとは

  • jQueryで使えるリッチエデイタ
  • Ctrl+Vで画像の挿入も可能
  • 割と古いライブラリであり、しかもググっても参考記事があまり出てこない
    https://premiumsoftware.net/cleditor/
  • ちょっとでも書き方がおかしいと、途端に無効化されてtextareaに変わってしまう。
  • JSエラーを出さずに無効化されることがあるため、原因調査が困難

環境

  • PHP
  • Zend Framework1

まず、view側にjavascriptにてCLEditorを定義

  • ダイアログ内での表示・非表示はcssで効かせるため、CLEditorにcssが効くようにする
<script type="text/javascript">
    var hogeEditor = null;
    $(function () {
        var $content = $("#dialog")
        hogeEditor = $content.cleditor({
            width: 750, //入力枠の横幅
            height: 300, //入力枠の縦
            useCSS: true, // cssを効かせるため、trueにする
            controls: // ここは最低一つ何か入れないとCLEditorが無効になるため、不要でも入れる
                "bold"
        });
    });
</script>

しかしこれだけでは効かない。controller側に下記を書く

    public function fugaAction()
    {
        // 下記2行はCLEditorをダイアログ上で実行する上で必要
        $options = ['layout' => 'mylayout', 'layoutPath' => {commonモジュールまでのパス}.'/views/layouts'];
        Zend_Layout::startMvc($options);
    {

あとはview側でcssを効かせて書くだけ。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0