z_bodya / yii-gallery-manager
Extension for yii, that allows to manage image galleries
Installs: 798
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 3
Forks: 2
Open Issues: 4
Type:yii-extension
Requires
- z_bodya/yii-image: dev-default
This package is not auto-updated.
Last update: 2024-12-21 15:54:54 UTC
README
Manual
-
Checkout source code to your project, for example to ext.galleryManager.
-
Install and configure image component(https://bitbucket.org/z_bodya/yii-image).
-
Import gallery models to project, by adding "ext.galleryManager.models.*" to import in config/main.php
-
Add GalleryController to application or module controllerMap.
-
Configure and save gallery model
:::php $gallery = new Gallery(); $gallery->name = true; $gallery->description = true; $gallery->versions = array( 'small' => array( 'resize' => array(200, null), ), 'medium' => array( 'resize' => array(800, null), ) ); $gallery->save();
-
Render widget for gallery created above:
:::php $this->widget('GalleryManager', array( 'gallery' => $gallery, 'controllerRoute' => '/admin/gallery', //route to gallery controller ));
Using GalleryBehavior
Using gallery behavior is possible to add gallery to any model in application.
To use GalleryBehavior:
-
Add it to your model:
Example: public function behaviors() { return array( 'galleryBehavior' => array( 'class' => 'GalleryBehavior', 'idAttribute' => 'gallery_id', 'versions' => array( 'small' => array( 'centeredpreview' => array(98, 98), ), 'medium' => array( 'resize' => array(800, null), ) ), 'name' => true, 'description' => true, ) ); }
-
Add gallery widget to your view:
Example: <h2>Product galley</h2> <?php if ($model->galleryBehavior->getGallery() === null) { echo '<p>Before add photos to product gallery, you need to save product</p>'; } else { $this->widget('GalleryManager', array( 'gallery' => $model->galleryBehavior->getGallery(), )); } ?>
Changing image versions for gallery associated with behavior
-
Update your model with new versions configuration
-
Run following code(best place for it - in migration):
:::php $models = Model::model()->findAll(); foreach($models as $model) $model->galleryBehavior->changeConfig();
Note: to run in migration you should define 'webroot' path alias.