Есть проблема - не выводятся фото в представлении. в таблицу загружаются, вызываю getUrl() выдает: /3/images/image-by-item-and-alias?item=Meny21&dirtyAlias=6bac56aba3-2.jpg.
Если изображения нет getUrl() выдает: /images/image-by-item-and-alias?item=&dirtyAlias=placeHolder.png
Подскажите, может кто сталкивался с данной проблемой.
Web.php:
Код: Выделить всё
'modules' => [
'yii2images' => [
'class' => 'rico\yii2images\Module',
//be sure, that permissions ok
//if you cant avoid permission errors you have to create "images" folder in web root manually and set 777 permissions
'imagesStorePath' => '@webroot/images/product', //path to origin images
'imagesCachePath' => '@webroot/images/cache', //path to resized copies
'graphicsLibrary' => 'GD', //but really its better to use 'Imagick'
'placeHolderPath' => '@webroot/images/product/noImage.png', // if you want to get placeholder when image not exists, string will be processed by Yii::getAlias
'imageCompressionQuality' => 100, // Optional. Default value is 85.
],
],
Код: Выделить всё
class Meny2 extends \yii\db\ActiveRecord
{
public function behaviors()
{
return [
'image' => [
'class' => 'rico\yii2images\behaviors\ImageBehave',
]
];
}
/**
* @inheritdoc
*/
public static function tableName()
{
return 'meny2';
}
public $image;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['type'], 'integer'],
[['name', 'title', 'description', 'link', 'img'], 'string', 'max' => 50],
[['image'], 'file', 'extensions' => 'png, jpg'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'Номер',
'name' => 'Наименование',
'type' => 'Раздел меню',
'image' => 'Картинка',
'title' => 'Заголовок',
'description' => 'Мета тег',
'link' => 'Ссылка',
];
}
public function upload(){
if ($this->validate()):
$path = 'images/product/'. $this->image->baseName . '.' . $this->image->extension;
$this->image->saveAs($path);
$this->attachImage($path);
return true;
else: return false;
endif;
}
}
Код: Выделить всё
public function actionUpdate_category($id)
{
$model = $this->findModel_category($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->image = UploadedFile::getInstance($model, 'image');
if ($model->image){
$model->upload();
}
//print_r($model); die;
//Yii::$app->session->setFlash('succes', "Товар {$model->name} обновлен");
return $this->redirect(['view_category', 'id' => $model->id]);
} else {
return $this->render('update_category', [
'model' => $model,
]);
}
}
Код: Выделить всё
<?php $img = $model->getImage();?>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'name',
'type',
[
'attribute' => 'image',
'value' => "<img src='{$img->getUrl()}'>",
'format' => 'html',
],
'title',
'description',
'link',
],
]) ?>