z_bodya/yii-gallery-manager

yii 的扩展,允许管理图像画廊

安装: 798

依赖项: 0

建议者: 0

安全: 0

星标: 6

关注者: 3

分支: 2

公开问题: 4

类型:yii-extension

dev-master 2015-03-18 11:55 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:34:47 UTC


README

手册

  1. 将源代码检出到您的项目,例如到 ext.galleryManager。

  2. 安装并配置图像组件(https://bitbucket.org/z_bodya/yii-image)。

  3. 将画廊模型导入项目,通过在 config/main.php 中添加 "ext.galleryManager.models.*" 来导入

  4. 将 GalleryController 添加到应用程序或模块控制器映射中。

  5. 配置并保存画廊模型

     :::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();
    
  6. 渲染创建的画廊的组件

     :::php
     $this->widget('GalleryManager', array(
         'gallery' => $gallery,
         'controllerRoute' => '/admin/gallery', //route to gallery controller
     ));
    

使用 GalleryBehavior

使用 GalleryBehavior 可以将画廊添加到应用程序中的任何模型。

要使用 GalleryBehavior

  1. 将其添加到您的模型中

     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,
             )
         );
     }
    
  2. 将画廊组件添加到您的视图中

     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(),
         ));
     }
     ?>
    

更改与行为关联的画廊的图像版本

  1. 使用新版本配置更新您的模型

  2. 运行以下代码(最佳位置是迁移中)

     :::php
     $models = Model::model()->findAll();
     foreach($models as $model) $model->galleryBehavior->changeConfig();
    

注意:在迁移中运行时,您应该定义 'webroot' 路径别名。