PHP code example of davidxu / yii2-imperavi-widget

1. Go to this page and download the library: Download davidxu/yii2-imperavi-widget 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/ */

    

davidxu / yii2-imperavi-widget example snippets


echo \davidxu\imperavi\Redactor::widget([
    'name' => 'redactor',
    'settings' => [
        'lang' => 'zh_cn',
        'imageUpload' => '/api/v1/redactor/upload',
        'minHeight' => 200,
        'plugins' => [
            'clips',
            'fullscreen',
        ],
        'clips' => [
            ['Lorem ipsum...', 'Lorem...'],
            ['red', '<span class="label-red">red</span>'],
            ['green', '<span class="label-green">green</span>'],
            ['blue', '<span class="label-blue">blue</span>'],
        ],
    ],
]);

use davidxu\imperavi\Redactor;

echo $form->field($model, 'content')->widget(Redactor::class, [
    'settings' => [
        'lang' => 'zh_cn',
        'imageUpload' => '/api/v1/redactor/upload',
        'minHeight' => 200,
        'plugins' => [
            'clips',
            'fullscreen',
        ],
        'clips' => [
            ['Lorem ipsum...', 'Lorem...'],
            ['red', '<span class="label-red">red</span>'],
            ['green', '<span class="label-green">green</span>'],
            ['blue', '<span class="label-blue">blue</span>'],
        ],
    ],
]);

echo \davidxu\imperavi\Redactor::widget([
    'selector' => '#my-textarea-id',
    'settings' => [
        'lang' => 'zh_cn',
        'imageUpload' => '/api/v1/redactor/upload',
        'minHeight' => 200,
        'plugins' => [
            'clips',
            'fullscreen',
        ],
        'clips' => [
            ['Lorem ipsum...', 'Lorem...'],
            ['red', '<span class="label-red">red</span>'],
            ['green', '<span class="label-green">green</span>'],
            ['blue', '<span class="label-blue">blue</span>'],
        ],
    ],
]);

// DefaultController.php
public function actions()
{
    return [
        'upload-local' => [
            'class' => 'davidxu\imperavi\actions\LocalUploadFileAction',
            'dnsBaseUrl' => 'http://my-site.com/', // Domain name or uri where files are stored, filelink will be dnsBaseUrl + url 
            'url' => 'images/', // Directory URL address, where files are stored.
            'path' => '@alias/to/my/path', // Or absolute path to directory where files are stored.
            'modelClass' => Attachment::class, // Please use migration first, if file/image info stored in DB
            'storeInDB' => true, // Default true
        ],
        'upload-qiniu' => [
            'class' => 'davidxu\imperavi\actions\QiniuUploadFileAction',
            'dnsBaseUrl' => 'http://my-site.com/', // Qiniu DNS domain name, filelink will be dnsBaseUrl + url 
            'url' => 'images/', // Qiniu key prefix, key will be url + filename.
            'modelClass' => Attachment::class, // Please use migration first
        ],
    ];
}

// View.php
echo \davidxu\imperavi\Redactor::widget([
    'selector' => '#my-textarea-id',
    'settings' => [
        'lang' => 'zh_cn',
        'minHeight' => 200,
        'imageUpload' => Url::to(['/default/image-upload']),
        'plugins' => [
            'imagemanager',
        ],
    ],
]);

echo \davidxu\imperavi\Redactor::widget([
    'selector' => '#my-textarea-id',
    'settings' => [
        'lang' => 'zh_cn',
        'minHeight' => 200,
        'plugins' => [
            'clips',
            'fullscreen'
        ]
    ],
    'plugins' => [
        'my-custom-plugin' => 'app\assets\MyPluginBundle',
    ],
]);
bash
$ php composer.phar