1. Go to this page and download the library: Download froala/yii2-froala-editor 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/ */
froala / yii2-froala-editor example snippets
echo froala\froalaeditor\FroalaEditorWidget::widget([
'name' => 'content',
'options' => [
// html attributes
'id'=>'content'
],
'clientOptions' => [
'toolbarInline'=> false,
'theme' =>'royal', //optional: dark, red, gray, royal
'language'=>'en_gb' // optional: ar, bs, cs, da, de, en_ca, en_gb, en_us ...
]
]);
public function actionUpload() {
$base_path = Yii::getAlias('@app');
$web_path = Yii::getAlias('@web');
$model = new UploadForm();
if (Yii::$app->request->isPost) {
$model->file = UploadedFile::getInstanceByName('file');
if ($model->validate()) {
$model->file->saveAs($base_path . '/web/uploads/' . $model->file->baseName . '.' . $model->file->extension);
}
}
// Get file link
$res = [
'link' => $web_path . '/uploads/' . $model->file->baseName . '.' . $model->file->extension,
];
// Response data
Yii::$app->response->format = Yii::$app->response->format = Response::FORMAT_JSON;
return $res;
}
namespace app\models;
use yii\base\Model;
use yii\web\UploadedFile;
/**
* UploadForm is the model behind the upload form.
*/
class UploadForm extends Model
{
/**
* @var UploadedFile|Null file attribute
*/
public $file;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
[['file'], 'file']
];
}
}