composer require alexantr/yii2-tinymce
composer require alexantr/yii2-elfinder
建立 @app/config/tinymce.php
return [
'plugins' => [
'anchor', 'charmap', 'code', 'help', 'hr',
'image', 'link', 'lists', 'media', 'paste',
'searchreplace', 'table',
],
'height' => 500,
'convert_urls' => false,
'element_format' => 'html',
'image_caption' => true,
'keep_styles' => false,
'paste_block_drop' => true,
'table_default_attributes' => new yii\web\JsExpression('{}'),
'table_default_styles' => new yii\web\JsExpression('{}'),
'invalid_elements' => 'acronym,font,center,nobr,strike,noembed,script,noscript',
'extended_valid_elements' => 'strong/b,em/i,table[style]',
// elFinder file manager https://github.com/alexantr/yii2-elfinder
'file_picker_callback' => alexantr\elfinder\TinyMCE::getFilePickerCallback(['elfinder/tinymce']),
];
中文問題
Download the TinyMCE 4 language pack from here.(https://www.tiny.cloud/docs-4x/language/tinymce4x_languages.zip)
Unpack the language .js file into your tinymce/langs folder.
====
field($model, 'content')->widget(TinyMce::className(), [ 'name' => 'attributeName', 'language' => 'zh_TW', 'presetPath' => '@app/config/tinymce.php', 'clientOptions' => [ 'height' => 500, ], ]) ?> ============================
@vendor\alexantr\yii2-tinymce\src\TinyMCE.php
protected function registerScripts() { $view = $this->getView(); TinyMCEAsset::register($view); WidgetAsset::register($view); $id = $this->options['id']; if ($this->language !== null && $this->language !== 'en') { $langFile = "langs/{$this->language}.js"; $langAssetBundle = TinyMceLangAsset::register($view); $langAssetBundle->js[] = $langFile; $this->clientOptions['language_url'] = $langAssetBundle->baseUrl . "/{$langFile}"; $this->clientOptions['language'] = "{$this->language}";//Language fix. Without it EN language when add some plugins like codemirror } $encodedOptions = !empty($this->clientOptions) ? Json::htmlEncode($this->clientOptions) : '{}'; $view->registerJs("alexantr.tinyMceWidget('$id', $encodedOptions);", View::POS_END); } ===============================