hugodias / cakegallery
CakePHP 的画廊插件
Requires
- php: >=5.3.0
- composer/installers: *
This package is not auto-updated.
Last update: 2024-09-28 18:26:30 UTC
README

CakeGallery 是一个用于管理相册、专辑和图片的 CakePHP 插件
使用 CakeGallery 您可以
- 创建专辑
- 为专辑添加标签、标题和状态(已发布或草稿)
- 同时上传多张图片
- 为您的图片创建多个版本(缩略图、裁剪、调整大小等)
- 将任何专辑与您的应用程序中的任何其他模型集成
视频和资源
安装教程: https://www.youtube.com/watch?v=OEgVQQTaWkE - 葡萄牙语
功能: https://www.youtube.com/watch?v=3gHRnCI2vHE
DEMO (旧版本): http://galleryopenshift-cakeupload.rhcloud.com/gallery
要求
要使用 CakeGallery,您需要以下要求
- CakePHP 2.x 应用程序
- PHP 5.3+ (捆绑 GD 2.0.28+ 用于图像处理)
- MySQL
- Apache
版本
2.0.0
开始之前
- 请确保您的
app/webroot/files
文件夹可写
向导安装(推荐)
- 从 Github 克隆或下载 Zip 文件
- 将
Gallery
文件夹复制到您的应用程序插件文件夹:app/Plugin/
- 确保您的
app/Plugin/Gallery/Config
文件夹可写(仅用于安装) - 打开您的
app/Config/bootstrap.php
文件,并添加以下代码
CakePlugin::load(array( 'Gallery' => array( 'bootstrap' => true, 'routes' => true )));
- 完成安装后,请访问您的浏览器并输入
http://your-app-url/gallery
,然后按照向导操作
手动安装
- 从 Github 克隆或下载 Zip 文件
- 将
Gallery
文件夹复制到您的应用程序插件文件夹:app/Plugin/
- 将
app/Plugin/Gallery/Config/config.php.install
文件重命名为 config.php - 将 SQL 文件
app/Plugin/Gallery/Config/cakegallery.sql
导入到您的数据库中 - 打开您的
app/Config/bootstrap.php
文件,并添加以下代码
CakePlugin::load(array( 'Gallery' => array( 'bootstrap' => true, 'routes' => true )));
-
在
app/webroot/files
内创建一个名为 gallery 的文件夹,并赋予它可写权限。(app/webroot/files/gallery
) -
在
http://your-app-url/gallery
上检查您的插件是否正常工作。
常见问题解答
图片不显示
如果您正在使用 Windows,可能会遇到图片无法渲染的情况。这是因为 Windows 目录分隔符引起的。要修复此问题,您可以使用此解决方案: http://stackoverflow.com/a/4095765/708385
如何将画廊附加到模型?
将画廊与您的应用程序中的模型集成非常简单,只需几秒钟,而且您不需要更改数据库。要开始,请打开您想附加画廊的模型,在这个例子中将是 Product.php
class Product extends AppModel{ public $name = 'Product'; }
现在您只需要在您的模型中添加 $actsAs 属性
class Product extends AppModel{ public $name = 'Product'; public $actsAs = array('Gallery.Gallery'); }
完成了!现在,当您在数据库中搜索此对象时,其图片将自动从插件中检索
$product = $this->Product->findById(10); // // array( // 'Product' => array( // 'id' => '1', // 'name' => 'My Product', // 'price' => '29.00' // ), // 'Gallery' => array( // 'Album' => array( // ... // ), // 'Picture' => array( // ... // ), // 'numPictures' => (int) 2 // ) // )
如果您想手动调用图片,您将需要禁用自动功能并自行调用
public $actsAs = array('Gallery.Gallery' => array('automatic' => false));
// Anycontroller.php $this->Product->id = 10; $this->Product->getGallery();
如何创建与模型相关联的新画廊?
您应该使用 Gallery 链接助手。它非常容易使用。
- 在控制器中指定 Gallery 助手
- 使用 gallery 链接助手传递模型和 ID
# ProductsController.php class ProductsController extends AppController { public $helpers = array('Gallery.Gallery'); }
# app/View/Products/view.ctp echo $this->Gallery->link('product', 10);
如何创建独立的画廊?(非相关画廊)
您可以创建一个不属于任何模型的独立画廊。要创建一个这样的画廊,您将使用上面的相同示例,但不需要任何参数
# anyview.ctp echo $this->Gallery->link();
如何更改图像调整大小尺寸?
有关图像的所有配置,您可以在 app/Plugin/Gallery/Config/bootstrap.php
中找到
$config = array( 'App' => array( # Choose what theme you want to use: # You can find all themes at Gallery/webroot/css/themes # Use the first name in the file as a parameter, eg: cosmo.min.css -> cosmo 'theme' => 'cosmo' ), 'File' => array( # Max size of a file (in megabytes (MB)) 'max_file_size' => '20', # What king pictures the user is allowed to upload? 'allowed_extensions' => array('jpg','png','jpeg','gif') ), 'Pictures' => array( # Resize original image. If you don't want to resize it, you should set a empty array, E.G: 'resize_to' => array() # Default configuration will resize the image to 1024 pixels height (and unlimited width) 'resize_to' => array(0, 1024, false), # Set to TRUE if you want to convert all png files to JPG (reduce significantly image size) 'png2jpg' => true, # Set the JPG quality on each resize. # The recommended value is 85 (85% quality) 'jpg_quality' => 85, # List of additional files generated after upload, like thumbnails, banners, etc 'styles' => array( 'small' => array(50, 50, true), # 50x50 Cropped 'medium' => array(255, 170, true), # 255#170 Cropped 'large' => array(0, 533, false) # 533 pixels height (and unlimited width) ) ) ); Configure::write('GalleryOptions', $config);
您可以创建任意多的样式,只需将其添加到样式数组中,未来的版本将在上传时创建。
注意:请勿修改默认名称,例如 medium 或 small。您可以安全地修改宽度和高度以及动作,但名称由插件使用,因此请不要更改。