Hi, thanks for taking the time.
I have this textarea on my form from 2amigos/TinyMce library that is supposed to take all the text written on it and save it in a newly created .txt file on my server.
It works perfectly offline(Xampp) but has an issue Online where it simply won’t upload any formatted text e.g bold text, underlined, paragraphed e.t.c. If I give it raw_text e.g Yii2 is amazing, then it works perfectly but if I Yii2 is amazing it won’t save, instead gives error (Page not Found).
I think the problem may be my Controller…but what do i know.
Kindly assist even if it means a better way of achieving my goal to save text from TinyMce in a .txt…Thanks in advance
UploadsController
public function actionBooks()
{
$this->layout = 'panel';
$model = new Uploads();
if ($model->load(Yii::$app->request->post()) && $model->save())
{
$book_name = $model->book_name;
$myfile = fopen('../../frontend/web/pdf/uploads/'.$book_name.'.txt', "w+");
$txt = $model->book;
fwrite($myfile, $txt);
$model->book_path = 'uploads/'.$book_name.'.txt';
$model->save();
fclose($myfile);
return $this->redirect(['view', 'id' => $model->book_id]);
}
return $this->render('books', [
'model' => $model,
]);
}
Uploads Model Class
public $book;
public static function tableName()
{
return 'uploads';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['book_name', 'book_author'], 'required'],
[['read_count'], 'integer'],
[['date_added'], 'safe'],
[['book_name', 'book_type','subject','read_level', 'book_author','book_path'], 'string', 'max' => 200],
[['book'],'safe'],
];
}
Form snippet
<?php $form = ActiveForm::begin(['options'=>['enctype'=>'multipart/form-data']]); ?>
...
<?= $form->field($model, 'book')->widget(TinyMce::className(), [
'options' => ['rows' => 8],
'language' => 'en',
'clientOptions' => [
'plugins' => [
"advlist autolink lists link image charmap print preview anchor wordcount pagebreak",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste"
],
'toolbar' => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
]
])->label('Paste Text Here:');?>
.....
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
<?php ActiveForm::end(); ?>