Yii2.0 UEditor編輯器使用


百度UEditor

GitHub地址 https://github.com/BigKuCha/yii2-ueditor-widget

安裝

Either run

$ php composer.phar require kucha/ueditor "*"
or add

"kucha/ueditor": "*"
to the require section of your composer.json file.

應用

controller:

public function actions()
{
    return [
        'upload' => [
            'class' => 'kucha\ueditor\UEditorAction',
        ]
    ];
}

view:

echo \kucha\ueditor\UEditor::widget([]);

或者:

<?= $form->field($model, 'content')->widget(\kucha\ueditor\UEditor::className(),['id'=>'content','name'=>'content','clientOptions' => [ //編輯區域大小 'initialFrameHeight' => '200',]]) ?>

說明

ueditor只支持2種語言,en-uszh-cn,默認跟隨系統語言 Yii::$app->language,可以通過2種方式設置,1.修改系統語言,在main.php(高級版) 或者web.php(基礎版)添加'language' => 'zh-CN',。2.實例化的時候配置語言選項,見下邊配置

配置相關

編輯器相關配置,請在view 中配置,參數為clientOptions,比如定制菜單,編輯器大小等等,具體參數請查看UEditor官網文檔
文件上傳相關配置,請在controller中配置,參數為config,例如文件上傳路徑等;更多參數請參照 config.php (跟UEditor提供的config.json一樣)

簡單實例:

public function actions()
{
    return [
        'upload' => [
            'class' => 'kucha\ueditor\UEditorAction',
            'config' => [
                "imageUrlPrefix"  => "http://www.baidu.com",//圖片訪問路徑前綴
                "imagePathFormat" => "/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}" //上傳保存路徑
            ],
        ]
    ];
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM