froala/yii2-froala-editor
Composer 安装命令:
composer require froala/yii2-froala-editor
包简介
A beautiful WYSIWYG HTML text editor based on HTML5 technology. Cross browser, with mobile support, high performance and Retina Ready modern design.
README 文档
README
Yii 2 widget for Froala Wysiwyg editor.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist froala/yii2-froala-editor
or add
"froala/yii2-froala-editor": "^3.2.5"
to the require section of your composer.json file.
Usage
Once the extension is installed, simply use it in your code by :
<?php echo froala\froalaeditor\FroalaEditorWidget::widget([ 'name' => 'content', 'options' => [ // html attributes 'id'=>'content' ], 'clientOptions' => [ 'toolbarInline'=> false, 'theme' =>'royal', //optional: dark, red, gray, royal 'language'=>'en_gb' // optional: ar, bs, cs, da, de, en_ca, en_gb, en_us ... ] ]); ?>
or use with a model:
<?php echo froala\froalaeditor\FroalaEditorWidget::widget([ 'model' => $model, 'attribute' => 'content', 'options' => [ // html attributes 'id'=>'content' ], 'clientOptions' => [ 'toolbarInline' => false, 'theme' => 'royal', //optional: dark, red, gray, royal 'language' => 'en_gb' // optional: ar, bs, cs, da, de, en_ca, en_gb, en_us ... ] ]); ?>
add Font-awesome cdn for font-awesome plugin
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
Upload example
Using the basic Yii template make a new folder under /web/ called uploads.
For controler:
public function actionUpload() { $base_path = Yii::getAlias('@app'); $web_path = Yii::getAlias('@web'); $model = new UploadForm(); if (Yii::$app->request->isPost) { $model->file = UploadedFile::getInstanceByName('file'); if ($model->validate()) { $model->file->saveAs($base_path . '/web/uploads/' . $model->file->baseName . '.' . $model->file->extension); } } // Get file link $res = [ 'link' => $web_path . '/uploads/' . $model->file->baseName . '.' . $model->file->extension, ]; // Response data Yii::$app->response->format = Yii::$app->response->format = Response::FORMAT_JSON; return $res; }
For model:
namespace app\models; use yii\base\Model; use yii\web\UploadedFile; /** * UploadForm is the model behind the upload form. */ class UploadForm extends Model { /** * @var UploadedFile|Null file attribute */ public $file; /** * @return array the validation rules. */ public function rules() { return [ [['file'], 'file'] ]; } }
For the view:
<?= \froala\froalaeditor\FroalaEditorWidget::widget([ 'name' => 'body', 'clientOptions' => [ 'toolbarInline'=> false, 'height' => 200, 'theme' => 'royal',//optional: dark, red, gray, royal 'language' => 'en_gb' , 'toolbarButtons' => ['fullscreen', 'bold', 'italic', 'underline', '|', 'paragraphFormat', 'insertImage'], 'imageUploadParam' => 'file', 'imageUploadURL' => \yii\helpers\Url::to(['site/upload/']) ], 'clientPlugins'=> ['fullscreen', 'paragraph_format', 'image'] ]); ?>
For full details on usage, see the documentation.
Custom Buttons Example
The custom Buttons can be defined in JS files anywhere you want, in this example in /basic/assets/ folder.
In the view:
<?php $this->registerJsFile('/basic/assets/alert.js', ['depends' => '\Froala\Editor\FroalaEditorAsset']);?> <?= \Froala\Editor\FroalaEditorWidget::widget([ 'name' => 'body', 'clientOptions' => [ 'toolbarInline' => false, 'height' => 200, 'theme' => 'royal',//optional: dark, red, gray, royal 'language' => 'en_gb', 'toolbarButtons' => ['fullscreen', 'bold', 'italic', 'underline', '|', 'paragraphFormat', 'insertImage', 'alert'] ], 'clientPlugins' => ['fullscreen', 'paragraph_format', 'image'] ]); ?>
In /basic/assets/alert.js:
FroalaEditor.DefineIcon('alert', {NAME: 'info'}); FroalaEditor.RegisterCommand('alert', { title: 'Hello', focus: false, undo: false, refreshAfterCallback: false, callback: function () { alert('Hello!'); } } );
For more details you can go to Custom Buttons
License
This package is available under MIT License. However, Froala editor requires purchasing a license from https://www.froala.com/wysiwyg-editor/pricing.
froala/yii2-froala-editor 适用场景与选型建议
froala/yii2-froala-editor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 241.28k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 03 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「text」 「javascript」 「wysiwyg」 「editor」 「html」 「rte」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 froala/yii2-froala-editor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 froala/yii2-froala-editor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 froala/yii2-froala-editor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
Common libraries used by Zimbra Api
PHP client for the Google Closure Compiler API in one file.
统计信息
- 总下载量: 241.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 33
- 依赖项目数: 6
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-20