今天用composer安装Ueditor,一直下载失败,不知道为什么,所以就手动安装了一下。记录一下安装步骤
GitHub地址 https://github.com/BigKuCha/yii2-ueditor-widget
首先下载ZIP格式的压缩包,把文件夹重命名为ueditor,并复制到common/widgets下,
修改文件夹下的ueditor.php、ueditorAction.php、ueditorAsset.php、upload.php 中的namespacen改为common\widgets\ueditor
namespace common\widgets\ueditor;
第二步、在调用的controller 文件中添加actions,比如我这里是用在ResourceController中的
<?php
/**
* ResourceController implements the CRUD actions for Resource model.
*/
class ResourceController extends Controller
{
//code
//...
public function actions()
{
return [
'upload' => [
'class' => 'common\widgets\ueditor\UeditorAction',
'config' => [
"imageUrlPrefix" => "",//图片访问路径前缀
"imagePathFormat" => "/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}",
"imageRoot" => Yii::getAlias("@webroot"),
],
],
];
}
}
第三步、调用的地方,我这里是_form.php中
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'content')->widget('common\widgets\ueditor\Ueditor',[
'options'=>[
'initialFrameWidth' => 650,
]
]) ?>
<div class="form-group">
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>