sjaakp / yii2-wysiwyg
Redactor editor for Yii2.x
Installs: 246
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- php: >=7.0.0
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-12-09 08:19:29 UTC
README
Redactor editor for Yii 2.x
This is a wrapper for the excellent Imperavi Redactor 'What-you-see-is-what-you-get' editor for the Yii 2.0 PHP Framework. It automatically loads any Redactor plugin needed.
A demonstration of yii2-wysiwyg is here.
Installation
The preferred way to install yii2-wysiwyg is through Composer.
Either add the following to the require section of your composer.json
file:
"sjaakp/yii2-wysiwyg": "*"
Or run:
composer require sjaakp/yii2-wysiwyg "*"
You can manually install yii2-wysiwyg by downloading the source in ZIP-format.
Redactor files
Redactor is proprietry software and is not available via Composer. You have to download it manually.
Yii2-wysiwyg assumes that the Redactor files (that is, the complete contents of
the 'redactor'
directory in the ZIP-file you get from Imperavi) live in '@app/redactor'
.
You can set another source path by setting parameter 'redactor'
in the application configuration file, usually called web.php
or main.php
in the config
directory, like so:
$params = [
'adminEmail' => ...,
'redactor' => <path to Redactor files, or alias>
];
$config = [
// ...
'params' => $params,
// ...
]
The path can and will most likely be set as an alias.
Using Wysiwyg
Wysiwyg is just an ordinary Yii 2 InputWidget. In a form, it can be used like this:
<?php
use sjaakp\wysiwyg\Wysiwyg;
?>
<?php $form = ActiveForm::begin([
// ... form options ...
]); ?>
... other fields ...
<?= $form->field($model, 'story')->widget(Wysiwyg::class, [
// ... Wysiwyg options ...
]) ?>
... more fields ...
<?php ActiveForm::end(); ?>
Like any InputWidget, Wysiwyg can also be used outside a form. In that case, it should be
associated with a name
and a value
:
<?php
use sjaakp\wysiwyg\Wysiwyg;
?>
<?= Wysiwyg::widget([
'name' => 'myWysiwyg',
'value' => 'Initial text...',
// ... other options ...
]) ?>
Options
Wysiwyg has al the properties of an InputWidget, plus the following:
- redactorOptions
array
the options for the Imperavi Redactor.Refer to the Imperavi Web page for possible options. There are lots of them! - includeCss
bool
whether CSS files should be registered. Set this to false in case you include the CSS in the sites main file.