PHP code example of bariew / yii2-imperavi-redactor

1. Go to this page and download the library: Download bariew/yii2-imperavi-redactor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bariew / yii2-imperavi-redactor example snippets


yii\imperavi\Widget::widget([
	// You can either use it for model attribute
	'model' => $my_model,
	'attribute' => 'my_field',

	// or just for input field
	'name' => 'my_input_name',

	// Some options, see http://imperavi.com/redactor/docs/
	'options' => [
		'toolbar' => false,
		'css' => 'wym.css',
	],
]);

yii\imperavi\Widget::widget([
	// Some options, see http://imperavi.com/redactor/docs/
	'options' => [],
]);

yii\imperavi\Widget::widget([
	'options' => [
		'lang' => 'ru',
	],
	'plugins' => [
		'fullscreen',
		'clips'
	]
]);

 // 1. Use your controller actions() method, e.g.:
    public function actions()
    {
        $path = "/files/".$this->module->id."/".$this->id."/".Yii::$app->user->id;
        return [
            'file-upload'    => [
                'class'         => 'yii\imperavi\actions\FileUpload',
                'uploadPath'    => Yii::getAlias('@app/web'.$path),
                'uploadUrl'     => $path
            ],
            'image-upload'    => [
                'class'         => 'yii\imperavi\actions\ImageUpload',
                'uploadPath'    => Yii::getAlias('@app/web'.$path),
                'uploadUrl'     => $path
            ],
            'image-list'    => [
                'class'         => 'yii\imperavi\actions\ImageList',
                'uploadPath'    => Yii::getAlias('@app/web'.$path),
                'uploadUrl'     => $path
            ],
        ];
    }
 // 2. Set upload options in your imperavi widget, e.g.:
    [
        'fileUpload'               => Url::toRoute(['file-upload', 'attr' => 'content']),
        'imageUpload'              => Url::toRoute(['image-upload', 'attr' => 'content']),
        'imageGetJson'             => Url::toRoute(['image-list', 'attr' => 'content']),
        'imageUploadErrorCallback' => new \yii\web\JsExpression('function(json) { alert(json.error); }'),
        'fileUploadErrorCallback'  => new \yii\web\JsExpression('function(json) { alert(json.error); }'),
    ]

 * You can also redefine action 'customRules' attribute for file validation.

php composer.phar