susilolab / yii2-redactor
Yii2 的 redactor 扩展。
v1.0.5
2016-06-30 13:18 UTC
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-18 20:35:59 UTC
README
Yii2 框架的 redactor 扩展。支持 jQuery >= 3
安装
安装此扩展的首选方式是通过 composer。
运行
php composer.phar require --prefer-dist susilolab/yii2-redactor "*"
或者
"susilolab/yii2-redactor": "*"
添加到你的 composer.json 的 require 部分。
配置
添加到配置文件(config/web.php 或 common\config\main.php)
'modules' => [
'redactor' => 'yii\redactor\RedactorModule',
],
或者如果你想更改上传目录,到路径/to/uploadfolder,默认值为 @webroot/uploads
'modules' => [
'redactor' => [
'class' => 'yii\redactor\RedactorModule',
'uploadDir' => '@webroot/path/to/uploadfolder',
'uploadUrl' => '@web/path/to/uploadfolder',
'imageAllowExtensions'=>['jpg','png','gif']
],
],
注意:你需要创建上传文件夹,并设置文件夹的 chmod 和安全权限
配置视图/表单
<?= $form->field($model, 'body')->widget(\yii\redactor\widgets\Redactor::className()) ?>
或者不使用 ActiveField
<?= \yii\redactor\widgets\Redactor::widget([
'model' => $model,
'attribute' => 'body'
]) ?>
或者配置高级 redactor 参考 文档
<?= $form->field($model, 'body')->widget(\yii\redactor\widgets\Redactor::className(), [
'clientOptions' => [
'imageManagerJson' => ['/redactor/upload/image-json'],
'imageUpload' => ['/redactor/upload/image'],
'fileUpload' => ['/redactor/upload/file'],
'lang' => 'zh_cn',
'plugins' => ['clips', 'fontcolor','imagemanager']
]
])?>
更改默认子文件夹 - 可选,只允许字母命名子文件夹 [a-zA-Z]
<?= $form->field($model, 'body')->widget(\yii\redactor\widgets\Redactor::className(), [
'clientOptions' => [
'imageManagerJson' => ['/redactor/upload/image-json', 'subfolder' => 'news'],
'imageUpload' => ['/redactor/upload/image', 'subfolder' => 'news'],
'fileUpload' => ['/redactor/upload/file', 'subfolder' => 'news'],
'lang' => 'zh_cn',
'plugins' => ['clips', 'fontcolor','imagemanager']
]
])?>
感谢!