Redactor Widget
Info: Redactor is OEM licensed for Yii and you can use it for free with the framework. See official widget.
$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'=>0664,
),
'imageUpload'=>array(
'class'=>'ext.redactor.actions.ImageUpload',
'uploadPath'=>'/path/to/uploads/folder',
'uploadUrl'=>'/url/to/uploads/folder',
'uploadCreate'=>true,
'permissions'=>0664,
),
'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); }'
),
),
));
yii-redactor is free and unencumbered public domain software.
Total 12 comments
I want to upload image but I hit a wall. I did not change everything, just default. Upload folder is OK but I cannot upload. When I load widget I get (on Firebug)
I do not know what to do. AFAICS all looks fine. Help!
Edit: I should add that I use Virtual host in apache! Full Trace
GET ?attr=awards_swa
500 Internal Server Error
admin.promusic.local
624 B
127.0.0.1:80
253ms ParamsHeadersResponseCacheHTMLCookies
PHP Error [2]
opendir(promusic/uploads/site/awards_swa): failed to open dir: No such file or directory (promusic/common/lib/Yii/utils/CFileHelper.php:160)
1 promusic/common/lib/Yii/utils/CFileHelper.php(160): opendir()
2 promusic/common/lib/Yii/utils/CFileHelper.php(87): findFilesRecursive()
3 promusic/backend/extensions/redactor/actions/ImageList.php(33): findFiles()
4 unknown(0): ImageList->run()
5 promusic/common/lib/Yii/web/actions/CAction.php(107): ReflectionMethod->invokeArgs()
6 promusic/common/lib/Yii/web/actions/CAction.php(73): ImageList->runWithParamsInternal()
7 promusic/common/lib/Yii/web/CController.php(309): ImageList->runWithParams()
8 promusic/common/lib/Yii/web/filters/CFilterChain.php(134): SiteController->runAction()
9 promusic/common/lib/Yii/web/filters/CFilter.php(41): CFilterChain->run()
10 promusic/common/lib/Yii/web/CController.php(1146): CAccessControlFilter->filter()
11 promusic/common/lib/Yii/web/filters/CInlineFilter.php(59): SiteController->filterAccessControl()
12 promusic/common/lib/Yii/web/filters/CFilterChain.php(131): CInlineFilter->filter()
13 promusic/common/lib/Yii/web/CController.php(292): CFilterChain->run()
14 promusic/common/lib/Yii/web/CController.php(266): SiteController->runActionWithFilters()
15 promusic/common/lib/Yii/web/CWebApplication.php(283): SiteController->run()
16 promusic/common/components/WebApplication.php(33): WebApplication->runController()
17 promusic/common/lib/Yii/web/CWebApplication.php(142): WebApplication->runController()
18 promusic/common/lib/Yii/base/CApplication.php(162): WebApplication->processRequest()
19 promusic/backend/www/index.php(43): WebApplication->run()
1 request
624 B
253ms
@Callum Rexter - I have had exact similar markup problem. This seems to be wrong with redactor.
I had to change to other options after having a lot of trouble with erroneous markup pf redactor.
I have installed this extension easily enough but when I use it I seem to be left with extra markup in my source.
Fore example when I tried to create a simple paragraph to test it out the markup was this:
I can't seem to find out why it does this, has anyone else had this?
If you want to have various languages at once on your page, there is many steps (v 8.2.2 now).
In each language file,
Replace var RELANG = {}; by
I add no translation for image upload, so i edited the redactor.js script line 3251, when is called dragupload function, add param
Next, line 4031 edit the construct function and add at the begenning
That's all.
Nice one to handle
@jacmoe Good news, thank you.
Since Yii has purchased an OEM license, we are all good, as long as we're using Redactor in combination with the Yii framework.
Text from official form site FAQ:
Can I use Redactor in my project, which is published under GPL, MIT, BSD, or other open-source/copyleft license?
Yes, go ahead! You just need to purchase the OEM license. No additional fees will be applied and there are no special terms or conditions, until Redactor is properly "linked" in your software.
However, keep in mind that Redactor is not an open-source product. It is proprietary commercial copyrighted software and we do not allow it's distribution under any open-source licenses. Think about Redactor as if it was a paid proprietary extension for your project.
imperavi.com/redactor/faq/
Looks like we can't use it without puscashing licence.
I just committed new default actions for image and file upload. What do you think?
https://github.com/janisto/yii-redactor
This one works with Redactor 8.0 or above.
What's the difference with http://www.yiiframework.com/extension/yii-redactorjs-wysiwyg-widget ? Could you make a note at the beginning to explain why a different project? Thanks a lot! E.
This editor seems very nice. Thanks!
Leave a comment
Please login to leave your comment.