Wallogit.com
2017 © Pedro Peláez
simditor widget
$ php composer.phar require felix33/yii2-simditor "*"
or add, (*1)
"felix33/yii2-simditor": "*"
to the require section of your composer.json file., (*2)
view:, (*3)
echo \felix33\simditor\Simditor::widget(['name' => 'xxxx']);
或者:, (*4)
echo $form->field($model,'colum')->widget('felix33\simditor\Simditor',[]);
view 中配置,参数为clientOptions,比如定制菜单,编辑器大小等等,具体参数请查看simditor官网文档。简单实例:, (*5)
use \felix33\simditor\Simditor;
echo Simditor::widget([
'name'=> 'simditor',
'value'=> '初始化内容..',
'clientOptions' => [
'placeHolder' => '这里输入内容...',
'toolbarFloat' => false,
// 工具栏
'toolbar' => [ 'title', '|', 'bold', 'italic',
'underline', 'strikethrough', 'color',
'fontScale', 'clearhtml', '|', 'ol', 'ul',
'blockquote', 'code', 'table', '|', 'link',
'image', 'hr', '|', 'indent', 'outdent',
'alignment', 'html', 'fullscreen', 'devices'
],
// 编辑器插入图片时使用的默认图片
'defaultImage' => '/images/image.png',
'upload' => [
// 文件上传的接口地址
'url' => Url::toRoute(['upload']),
// 键值对,指定文件上传接口的额外参数,上传的时候随文件一起提交
'params' => null,
// 服务器端获取文件数据的参数名
'fileKey' => 'fileData',
'connectionCount' => 3,
'leaveConfirm' => '正在上传文件'
]
]);
controller中配置简单实例:
controller:, (*6)
public function actions()
{
return [
'upload' => [
'class' => 'felix33\simditor\SimditorAction'
]
];
}
或者:, (*7)
public function actions()
{
return [
'upload' => [
'class' => 'felix33\simditor\SimditorAction',
'config' => [
// 文件字段
"fileKey" => "fileData",
// 图片访问路径前缀
"urlPrefix" => Yii::getAlias('@web'),
// 上传保存路径
"uploadRoot" => Yii::getAlias("@webroot"),
// 上传路径格式化
"pathFormat" => "/upload/{yyyy}{mm}{dd}/{time}{rand:6}"
],
]
];
}