<?php
echo $form->field($model, 'body')->widget(
\froala\froalaeditor\FroalaEditorWidget::className(),
[
'options' => [
],
'csrfCookieParam' => '_csrf',
'clientOptions' => [
'toolbarInline' => false,
'height' => 350,
'imageDefaultWidth' => 1000,
'theme' => 'royal',
'language' => 'en_gb',
//'toolbarButtons' => ['fullscreen', 'bold', 'italic', 'underline', '|', 'paragraphFormat', 'insertImage'],
'imageUploadURL' => Url::to(['/file-storage/upload-froala']),
'fileUploadURL' => Url::to(['/file-storage/upload-froala']),
'imageManagerLoadURL' => Url::to(['/file-storage/file-froala'])
],
//'clientPlugins' => [ 'fullscreen', 'paragraph_format', 'image', 'file', 'image_manager' ]
]
)
?>
Config with Yii 2 File Kit (https://github.com/trntv/yii2-file-kit)
/*
* Action Upload File For Froala WYSIWYG HTML Editor
*
* @param file $file
*
* @return file infor
* */
public function actionUploadFroala()
{
// Get file link
$fileName = 'file';
$logoFile = UploadedFile::getInstanceByName($fileName);
$filePath = Yii::$app->fileStorage->save($logoFile);
$baseUrl = Yii::$app->fileStorage->baseUrl;
$imageUrl = $baseUrl . '/' . $filePath;
$res = ['link' => $imageUrl];
// Response data
Yii::$app->response->format = Yii::$app->response->format = Response::FORMAT_JSON;
return $res;
}
/*
* List Image
* */
public function actionFileFroala()
{
$dataFileItem = FileStorageItem::find()
->limit(10)
->all();
$dataImage = [];
/** @var FileStorageItem $item */
foreach ($dataFileItem as $item) {
if (Yii::$app->fileStorage->getFilesystem()->has($item->path)) {
$dataDetail = [];
$dataDetail['url'] = $item->base_url . '/' . $item->path;
$dataImage [] = $dataDetail;
}
}
$res = $dataImage;
// Response data
Yii::$app->response->format = Yii::$app->response->format = Response::FORMAT_JSON;
return $res;
}