百度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-us
和zh-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}" //上傳保存路徑 ], ] ]; }