netpc/yii2-ueditor
Composer 安装命令:
composer require netpc/yii2-ueditor
包简介
yii2整合ueditor富文本编辑器
关键字:
README 文档
README
yii2整合ueditor富文本编辑器
基于yii2官方扩展yiisoft/yii2-imagine和UEditor资源包[1.4.3.3 PHP 版本] UTF-8版开发
扩展特点:
1. 支持修改尺寸
2. 支持文字水印
3. 支持图片水印
4. 支持多图上传
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist netpc/yii2-ueditor "*"
composer require --prefer-dist netpc/yii2-ueditor:"dev-master"
or add
"netpc/yii2-ueditor": "*"
to the require section of your composer.json file.
Update
composer require netpc/yii2-ueditor
Usage
Once the extension is installed, simply use it in your code by :
前端视图:
use netpc\ueditor\UEditor; <?= UEditor::widget([]); //如无设置id和name,默认从w1自动递增 ?> <?= UEditor::widget([ 'id' => 'txtContent', 'name' => 'txtContent', 'options' => [ 'focus' => true, 'toolbars' => [ ['fullscreen', 'source', 'undo', 'redo', 'bold'], ], 'serverUrl' => ['/ueditor/index'],//serverUrl指向自定义后端地址 'catchRemoteImageEnable' => false,//默认抓取远程图片 ], 'attributes' => [ 'style' => 'height:500px' ], ]); ?> <?= $form->field($model, 'content')->textarea(['rows' => 6])->widget(UEditor::className(), [ 'options' => [//详细参考ueditor.config.js 'focus' => true, 'toolbars' => [ [ 'fullscreen', 'source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight', '|', 'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|', 'directionalityltr', 'directionalityrtl', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|', 'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|', 'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|', 'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|', 'print', 'preview', 'searchreplace', 'drafts', 'help' ], ], 'catchRemoteImageEnable' => false,//设置是否抓取远程图片 ], 'attributes' => [ 'style' => 'height:80px' ] ]) ?>
后端处理:
通过配置controllerMap路由映射到对应的控制器上
如下:ueditor/index映射到'netpc\ueditor\UEditorController'
有时候后台管理项目backend上传图片和文件等附件,是需要放到前端项目frontend的web目录下,或其它前端项目。
这时候可以配置参数config['webroot']上传目录路径,不设置默认上传到当前项目web目录。
配合imageUrlPrefix设置图片访问路径前缀可以实现图片独立域名
<?php $config = [ 'components' => [ 'request' => [ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 'cookieValidationKey' => '', ], ], 'controllerMap' => [ 'ueditor' => [ 'class' => 'netpc\ueditor\UEditorController', 'config' => [ //server config @see http://fex.baidu.com/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/',//图片管理列表 //'imageUrlPrefix' => '//img.netpc.com.cn',//图片访问路径前缀 //'imageManagerUrlPrefix' => '//img.netpc.com.cn',//图片管理列表访问路径前缀 'fileManagerListPath' => '/upload/file/',//文件管理列表 // 'fileUrlPrefix' => '//file.netpc.com.cn',//图片访问路径前缀 // 'fileManagerUrlPrefix' => '//file.netpc.com.cn',//文件管理列表访问路径前缀 // 'webroot' => Yii::getAlias('@frontend/web'),//上传图片文件根目录 默认是当前项目Web ], 'resize' => [//修改尺寸,上传图片自动修改为600像素宽度 'width' => 600,//小于600不处理 'height' => 0,//高度为0 不限制高度 ], 'watermark' => [//生成水印需官方扩展支持 composer require --prefer-dist yiisoft/yii2-imagine 'path' => '@vendor/netpc/yii2-ueditor/assets/images/watermark.png', //图片水印路径 '@webroot/images/watermark.png' 'text' => 'netpc.com.cn测试', //文字水印内容 //'quality' => 90, //压缩质量 //'fontsize' => 50, //字体大小 默认14 //'fontpath'=> '@webroot/fonts/xxx.ttf',//字体路径 默认Alibaba-PuHuiTi-Heavy.otf不到2m免费商用 //'fontcolor'=> '#000000',//字体颜色 默认#000000 'point' => [-80, -10],//x,y对应width,height 正数实际像素移动 负数图片宽、高减去像素移动 [10, -30]左下 [-200, 10]右上 [-200, -30] 右下 'center' => true,//当center为真时以图片中心点为开始根据point正负偏移,正右移动,负左移动。 'width' => 100,//小于宽度不加水印 'height' => 100,//小于高度不加水印 ], ] ], ];
相关链接
@see http://fex.baidu.com/ueditor/
@see https://github.com/yiisoft/yii2-imagine
netpc/yii2-ueditor 适用场景与选型建议
netpc/yii2-ueditor 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 37 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extension」 「yii2」 「ueditor」 「netpc」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 netpc/yii2-ueditor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 netpc/yii2-ueditor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 netpc/yii2-ueditor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
Adds more BBCode
UEditor 是一套开源的在线HTML编辑器,主要用于让用户在网站上获得所见即所得编辑效果,开发人员可以用 UEditor 把传统的多行文本输入框(textarea)替换为可视化的富文本输入框。
统计信息
- 总下载量: 37
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-27