PHP code example of xing.chen / yii2-ueditor

1. Go to this page and download the library: Download xing.chen/yii2-ueditor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xing.chen / yii2-ueditor example snippets


class UeditorController extends \xing\ueditor\UEditorController
{
    public function init(){
        parent::init();
        //do something
        //这里可以对扩展的访问权限进行控制
    }
    
    public function actionConfig(){
        //do something
        //这里可以对 config 请求进行自定义响应,不需要定制的就删除此方法
    }
    
    /**
     * 定制上传方法(覆盖父方法)
     * @param $fieldName
     * @param $config
     * @param $base64
     * @return array
     */
    protected function upload($fieldName, $config, $base64 = 'upload')
    {
        $instance = UploadLogic::getInstance('ali');
        $return = $instance->upload($fieldName, 'store');
        return [
            'state' => 'SUCCESS',
            'url' => $return['url'],
            'thumbnail' => $return['url'],
            'width' => 500,
            'height' => 500
        ];
    }
    // more modify ...
    // 更多的修改
}

    'controllerMap' => [
        'ueditor' => [
            'class' => 'xing\ueditor\UEditorController',
        ]
    ],


    'controllerMap' => [
        'ueditor' => [
            'class' => 'xing\ueditor\UEditorController',
            'thumbnail' => false,//如果将'thumbnail'设置为空,将不生成缩略图。
            'watermark' => [    //默认不生存水印
                'path' => '', //水印图片路径
                'position' => 9 //position in [1, 9],表示从左上到右下的 9 个位置,即如1表示左上,5表示中间,9表示右下。
            ],
            'zoom' => ['height' => 500, 'width' => 500], //缩放,默认不缩放
            'config' => [
                //server config @see http://fex-team.github.io/ueditor/#server-config
                'imagePathFormat' => '/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}',
                'scrawlPathFormat' => '/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}',
                'snapscreenPathFormat' => '/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}',
                'catcherPathFormat' => '/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}',
                'videoPathFormat' => '/upload/video/{yyyy}{mm}{dd}/{time}{rand:6}',
                'filePathFormat' => '/upload/file/{yyyy}{mm}{dd}/{rand:4}_{filename}',
                'imageManagerListPath' => '/upload/image/',
                'fileManagerListPath' => '/upload/file/',
            ]
        ]
    ],

    'thumbnail' => ['height' => 200, 'width' => 200]

<?= $form->field($model, 'content')->widget(\xing\ueditor\UEditor::className()) 

<?= \xing\ueditor\UEditor::widget([
    'model' => $model,
    'attribute' => 'content',
]) 

<?= \xing\ueditor\UEditor::widget([
    'model' => $model,
    'attribute' => 'content',
    'config' => [
        //client config @see http://fex-team.github.io/ueditor/#start-config
        'serverUrl' => ['/ueditor/index'],//确保serverUrl正确指向后端地址
        'lang' => 'zh-cn',
        'iframeCssUrl' => Yii::getAlias('@web') . '/static/css/ueditor.css',// 自定义编辑器内显示效果
    ]
]) 

<?= \xing\ueditor\UEditor::widget([
    'name' => $name,
    'value' => $value,
])