Answer the question
In order to leave comments, you need to log in
No picture image in yii2 admin although it is loading, instead of photo icon, oc linux?
SiteController.php in backend/controllers
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index', 'save-redactor-img','save-img'],
'allow' => true ,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
public function actionSaveRedactorImg($sub='main'){
$this->enableCsrfValidation = false;
if (Yii::$app->request->isPost) {
$dir = Yii::getAlias('@images').'/'.$sub.'/';
if(!file_exists($dir)){
FileHelper::createDirectory($dir);
}
$result_link = str_replace('admin.','',Url::home(true)).
$file = UploadedFile::getInstanceByName('file');
$model = new DynamicModel(compact('file'));
$model->addRule('file', 'image')->validate();
if ($model->hasErrors()) {
$result = [
'error' => $model->getFirstError('file')
];
} else {
$model->file->name = strtotime('now').'_'.Yii::$app->getSecurity()->generateRandomString(6) . '.' . $model->file->extension;
if ($model->file->saveAs($dir . $model->file->name)) {
$imag = Yii::$app->image->load($dir .
$imag->resize(800, NULL, Yii\image\drivers\Image::PRECISE)->save($dir . $model->file->name, 85);
$result = ['filelink' => $result_link . $model->file->name, 'filename'=>$model->file->name];
} else {
$result = [
'error' => Yii::t('vova07/imperavi', 'ERROR_CAN_NOT_UPLOAD_FILE')
];
}
}
Yii::$app->response->format = Response::FORMAT_JSON;
return $result;
}else {
throw new BadRequestHttpException('Only POST is allowed');
ImageManager.php in common/models
class ImageManager extends \yii\db\ActiveRecord
{
public $attachment;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'image_manager';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name', 'class', 'item_id'], 'required'],
[['item_id'], 'integer' ] ,
[['name', 'class', 'alt'], 'string', 'max' => 150],
[['attachment'], '
image'], ];
}
form.php in backend/views/blog
<?= $form->field($model, 'text')->widget(Widget::className(),[
'settings' => [
'lang' => 'en ',
'minHeight' => 200,
'formatting' => ['p', 'blockquote', 'h2', 'h1'],
'imageUpload' => \yii\helpers\Url::to(['/ site/save-redactor-img','sub'=>'blog']),
'plugins' => [
'clips',
'fullscreen',
]
]
]) ?>
I can't figure it out in the code or Linux? apart from me ;) tell me please.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question