Yii Widget for Redactor - Fantastic WYSIWYG editor on jQuery
- Redactor 8.0 or above
- Yii 1.1.10 or above (Redactor requires jQuery 1.7.1)
- Download yii-redactor or Clone the files
- Extract into the widgets or extensions folder
- Download Redactor and language files if needed
- Extract Redactor files
- redactor.css -> redactor/assets/css/
- redactor.js and redactor.min.js -> redactor/assets/js/
- language files -> redactor/assets/js/lang/
$this->widget('ext.redactor.ERedactorWidget',array(
'model'=>$model,
'attribute'=>'some_attribute',
));
$this->widget('ext.redactor.ERedactorWidget',array(
'model'=>$model,
'attribute'=>'some_attribute',
// Redactor options
'options'=>array(
'lang'=>'fi',
),
));
$this->widget('ext.redactor.ERedactorWidget',array(
'name'=>'some_name',
'value'=>'some_value',
// Redactor options
'options'=>array(),
));
$this->widget('ext.redactor.ERedactorWidget',array(
// the textarea selector
'selector'=>'.redactor',
// Redactor options
'options'=>array(),
));
return array(
// application components
'components'=>array(
(...)
// Defaults to Widgets
'widgetFactory' => array(
'widgets' => array(
'ERedactorWidget' => array(
'options'=>array(
'lang'=>'fi',
'buttons'=>array(
'formatting', '|', 'bold', 'italic', 'deleted', '|',
'unorderedlist', 'orderedlist', 'outdent', 'indent', '|',
'image', 'video', 'link', '|', 'html',
),
),
),
),
),
(...)
),
);
Let's assume we are using Post model and PostController.
Create "uploads" folder to application root, add write permissions to it and add actions to PostController with default values.
class PostController extends Controller
{
public function actions()
{
return array(
'fileUpload'=>'ext.redactor.actions.FileUpload',
'imageUpload'=>'ext.redactor.actions.ImageUpload',
'imageList'=>'ext.redactor.actions.ImageList',
);
}
...
}
Or let actions create "uploads" folder automatically to application root folder.
class PostController extends Controller
{
public function actions()
{
return array(
'fileUpload'=>array(
'class'=>'ext.redactor.actions.FileUpload',
'uploadCreate'=>true,
),
'imageUpload'=>array(
'class'=>'ext.redactor.actions.ImageUpload',
'uploadCreate'=>true,
),
'imageList'=>array(
'class'=>'ext.redactor.actions.ImageList',
),
);
}
...
}
Or add actions to PostController with other custom values.
class PostController extends Controller
{
public function actions()
{
return array(
'fileUpload'=>array(
'class'=>'ext.redactor.actions.FileUpload',
'uploadPath'=>'/path/to/uploads/folder',
'uploadUrl'=>'/url/to/uploads/folder',
'uploadCreate'=>true,
'permissions'=>0755,
),
'imageUpload'=>array(
'class'=>'ext.redactor.actions.ImageUpload',
'uploadPath'=>'/path/to/uploads/folder',
'uploadUrl'=>'/url/to/uploads/folder',
'uploadCreate'=>true,
'permissions'=>0755,
),
'imageList'=>array(
'class'=>'ext.redactor.actions.ImageList',
'uploadPath'=>'/path/to/uploads/folder',
'uploadUrl'=>'/url/to/uploads/folder',
),
);
}
...
}
Add widget to the form view.
$attribute='content';
$this->widget('ext.redactor.ERedactorWidget',array(
'model'=>$model,
'attribute'=>$attribute,
'options'=>array(
'fileUpload'=>Yii::app()->createUrl('post/fileUpload',array(
'attr'=>$attribute
)),
'fileUploadErrorCallback'=>new CJavaScriptExpression(
'function(obj,json) { alert(json.error); }'
),
'imageUpload'=>Yii::app()->createUrl('post/imageUpload',array(
'attr'=>$attribute
)),
'imageGetJson'=>Yii::app()->createUrl('post/imageList',array(
'attr'=>$attribute
)),
'imageUploadErrorCallback'=>new CJavaScriptExpression(
'function(obj,json) { alert(json.error); }'
),
),
));
- Update readme.
- Default actions for image and file upload.
- Initial version.
yii-redactor is free and unencumbered public domain software.