Closed bahrammzm closed 7 years ago
public function behaviors()
{
return [
'galleryBehavior' => [
'class' => GalleryBehavior::className(),
'type' => 'gallery',
'extension' => 'jpg',
'directory' => Yii::getAlias('@webroot') . '/uploads',
'url' => Yii::getAlias('@web') . '/uploads',
'versions' => [
'small' => function ($img) {
/** @var \Imagine\Image\ImageInterface $img */
return $img
->copy()
->thumbnail(new \Imagine\Image\Box(200, 200));
},
'medium' => function ($img) {
/** @var Imagine\Image\ImageInterface $img */
$dstSize = $img->getSize();
$maxWidth = 800;
if ($dstSize->getWidth() > $maxWidth) {
$dstSize = $dstSize->widen($maxWidth);
}
return $img
->copy()
->resize($dstSize);
},
]
]
];
}
public function actions()
{
return [
'galleryApi' => [
'class' => GalleryManagerAction::className(),
'types' => [
'gallery' => GalleryImage::className()
]
],
];
}
<?php
echo GalleryManager::widget(
[
'model' => $model,
'behaviorName' => 'galleryBehavior',
'apiRoute' => 'gallery-image/galleryApi'
]
);
foreach($model->getBehavior('galleryBehavior')->getImages() as $image) {
echo Html::img($image->getUrl('medium'));
}
?>
check upload limitations in your php and webserver config:
php - upload_max_filesize
, post_max_size
webserver - client_max_body_size
(for nginx)
also issue can be because of memory_limit
in php (image processing can require a lot of ram)
what is size of image you are trying to upload? (both file size and dimensions)
i checked these options inside php.ini file memory_limit = 128M upload_max_filesize = 64M post_max_size = 3M
still issue is remaining ! also i inserted a row in mysql and an image inside uploads folder with same name , But gallery manager does not show any image !
Can you show content of error response you are getting from server?
my fille is less than 1mb . as i said internal server error 500 in AjaxUpload
open response details in network tab
select failed request and look to response content there…
it return PHP Fatal Error Call to a member function getBehavior() on a non-object
For use this package i have to login as a User to my site Or it's possible as Guest user??
i found out that the issue occur when i want insert new row in table ! whereas in update it work properly . now how can i handle it for insert new row in table ?
I have the same problem Call to a member function getBehavior() on null
i found out that the issue occur when i want insert new row in table ! whereas in update it work properly . now how can i handle it for insert new row in table ?
you mean uploading gallery photo to before creating db record for gallery it would belong to? that is not possible with current implementation.
I have the same problem Call to a member function getBehavior() on null
I do not see galleryId
in request url, but it should be there…
Can you upload your code to make it easier to pinpoint what is the reason?
I do not see galleryId in request url, but it should be there… Can you upload your code to make it easier to pinpoint what is the reason?
Model:
`use zxbodya\yii2\galleryManager\GalleryBehavior; class Gallerys extends \yii\db\ActiveRecord {
public static function tableName()
{
return 'gallery_image';
}
public function behaviors()
{
return [
'galleryBehavior' => [
'class' => GalleryBehavior::className(),
'type' => 'gallerys',
'extension' => 'jpg',
'directory' => Yii::getAlias('@webroot') . '/im/gallery',
'url' => Yii::getAlias('@web') . '/im/gallery',
'versions' => [
'small' => function ($img) {
/** @var \Imagine\Image\ImageInterface $img */
return $img
->copy()
->thumbnail(new \Imagine\Image\Box(200, 200));
},
'medium' => function ($img) {
/** @var Imagine\Image\ImageInterface $img */
$dstSize = $img->getSize();
$maxWidth = 800;
if ($dstSize->getWidth() > $maxWidth) {
$dstSize = $dstSize->widen($maxWidth);
}
return $img
->copy()
->resize($dstSize);
},
]
]
];
}
public function rules()
{
return [
[['ownerId'], 'required'],
[['rank'], 'integer'],
[['description'], 'string'],
[['type', 'ownerId', 'name'], 'string', 'max' => 255],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'type' => 'Тип',
'ownerId' => 'ID Владельца',
'rank' => 'Позиция',
'name' => 'Название',
'description' => 'Описание',
];
}
}`
Controller: `namespace app\modules\backend\controllers;
use app\modules\backend\models\Gallerys; use Yii; use yii\web\Controller; use yii\web\NotFoundHttpException; use zxbodya\yii2\galleryManager\GalleryManagerAction;
class GallerysController extends Controller {
public function actions()
{
return [
'galleryApi' => [
'class' => GalleryManagerAction::className(),
// mappings between type names and model classes (should be the same as in behaviour)
'types' => [
'gallerys' => Gallerys::className()
]
],
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
public function actionIndex() {
$model = new Gallerys();
return $this->render('index', [
'model' => $model,
]);
}`
View: `<?php
use yii\helpers\Html; use zxbodya\yii2\galleryManager\GalleryManager; ?>
$model = new Gallerys();
you can not upload images to new gallery. it should be saved before you can show widget.
you can not upload images to new gallery. it should be saved before you can show widget.
Can you please show an example of action to render view with existing record? And how can i save record if it's empty before view render?
@ivanuz what do you mean? it is in readme - just load existing model, and then pass it into the view…
Thanks a lot! Just created an empty record and it works!
$model = Gallerys::findOne('1');
return $this->render('index', [
'model' => $model,
]);
when i select image for upload ,it return follow error Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:81/en/gallery-image/galleryApi?behaviorName=galleryBehavior&action=ajaxUpload