Home > Article > PHP Framework > How to use Ueditor in Yii?
Yii How to use Ueditor?
First create a new public directory and uploads directory in the entry file directory;
Then download Ueditor, unzip it to the public directory;
Then import the "ueditor for yii2" library, and define a custom upload directory;
"imagePathFormat": "/uploads/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}", "scrawlPathFormat": "/uploads/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}"
Finally, introduce it in the view and use it.
<?php use yii\helpers\Html; use yii\bootstrap\ActiveForm; //引入百度编辑器 $this->registerJsFile('@web/public/ueditor/ueditor.config.js');//注册自定义js $this->registerJsFile('@web/public/ueditor/ueditor.all.min.js'); $this->registerJsFile('@web/public/ueditor/lang/zh-cn/zh-cn.js'); ?> <script> $(function(){ var ue = UE.getEditor('editor'); }) </script> <style> .inline .radio,.inline .checkbox{display: inline-block;margin: 0 5px;} #editor{margin-top: 20px;padding:0;margin:20px 0;width:100%;height:auto;border: none;} </style> <?php $form=ActiveForm::begin([ 'id'=>'upload', 'enableAjaxValidation' => false, 'options'=>['enctype'=>'multipart/form-data'] ]); ?> <?= $form->field($model,'title')->textInput();?> <?= $form->field($model, 'image')->fileInput();?> <?= $form->field($model,'content')->textarea(['rows'=>6,'id'=>'editor','class'=>'col-sm-1 col-md-12']);?> <?= Html::submitButton('提交', ['class'=>'btn btn-primary','name' =>'submit-button']) ?> <?php ActiveForm::end();?>
Recommended tutorial: "Yii Tutorial"
The above is the detailed content of How to use Ueditor in Yii?. For more information, please follow other related articles on the PHP Chinese website!