cloudinary/cloudinary_cake_php
Composer 安装命令:
composer require cloudinary/cloudinary_cake_php
包简介
Cloudinary Cake PHP SDK
README 文档
README
Cloudinary CakePHP plugin provides seemless integration of Cloudinary services with CakePHP framework for simple and efficient management of applications images
Explore the PhotoAlbumCake sample for usage example.
Requirements
- PHP 5.3 or higher
- CakePHP 2.x
Installation
Composer
-
Create a new directory for myapp
mkdir myapp cd myapp -
Install CakePHP using composer (based on CakePHP Cookbook
-
Setup Composer and get CakePHP:
echo '{}' > composer.json composer config vendor-dir Vendor composer config repositories.0 pear 'http://pear.cakephp.org' composer require 'pear-cakephp/cakephp:>=2.4.0' -
Bake a new project
Vendor/bin/cake bake project . -
You may define
CAKE_CORE_INCLUDE_PATHto a relative path as suggested in the cookbook by adding the following towebroot/index.php:define( 'CAKE_CORE_INCLUDE_PATH', ROOT . DS . APP_DIR . '/Vendor/pear-pear.cakephp.org/CakePHP' ); -
Add the following lines to
Config/bootstrap.php:// Load composer autoload. require APP . '/Vendor/autoload.php'; // Auto load CloudinaryCake plugin \CloudinaryCakeLoader::load();
-
-
Install Cloudinary CakePHP
composer require 'cloudinary/cloudinary_cake_php:>=1.0.0' -
Configure Cloudinary using the
CLOUDINARY_URLenvironment variable, or theConfig/CloudinaryPrivate.phpconfiguration file
Manual
-
Create a CakePHP project
-
Download cloudinary_php from here
-
Extract the cloudinary_php archive into
vendorslibrary -
Download cloudinary_cake_php from here
-
Extract the cloudinary_cake_php archive into
vendorslibrary -
Configure cloudinary
- Environment variable -
export CLOUDINARY\_URL = "cloudinary://API_KEY:API_SECRET@CLOUD_NAME"(Check your settings in Cloudinary console) - Create
app/Config/CloudinaryPrivate.phpusingvendors/cloudinary_php/samples/PhotoAlbumCake/Config/CloudinaryPrivate.php.sample
- Environment variable -
-
Load the cloudinary plugin by adding the following lines to
app/Config/bootstrap.php:// Load plugin CakePlugin::load('CloudinaryCake', array('bootstrap' => true, 'routes' => false, 'path' => ROOT . DS 'vendors' . DS 'cloudinary_php' . DS . 'cake_plugin' . DS . 'CloudinaryCake' . DS)); // required when using `CloudinaryPrivate.php` for cloudinary configuration Configure::load('CloudinaryPrivate'); \Cloudinary::config(Configure::read('cloudinary'));
Usage
CloudinaryBehavior
CloudinaryBehavior adds Cloudinary support for CakePHP Models. It helps storing references to cloudinary images in a simple text field of your model.
Setup
Assuming you have a Photo model with cloudinaryIdentifier text field for storing cloudinary images references - you can add the following code to your model
Models/photo.php:
[...]
class Photo extends AppModel {
public $actsAs = array('CloudinaryCake.Cloudinary' => array('fields' => array('cloudinaryIdentifier')));
[...]
}
Usage
This will allow you to access the cloudinaryIdentifier as a CloudinaryField. Here's a sample controller code -
Controller/PhotosController.php:
class PhotosController extends AppController {
[...]
// set the specified Photo's image to the default one
public function set_default_image($id) {
$options = array('conditions' => array('Photo.' . $this->Photo->primaryKey => $id));
$photo = $this->Photo->find('first', $options);
$photo['Photo']['cloudinaryIdentifier']->upload(DEFAULT_IMAGE_PATH);
$this->Photo->save($photo);
}
[...]
// Creates a new image from post data. Sets $image_url to the cloudinary url of the image with the given transformation.
public function add() {
$this->Photo->create();
$success = $this->Photo->save($this->request->data);
if ($success) {
$image_url = $this->Photo->data['Photo']['cloudinaryIdentifier']->url(array(
"width" => 100, "height" => 100, "crop" => "fill"));
}
$this->set('photo', $this->Photo->data);
}
[...]
}
CloudinaryHelper
CloudinaryHelper is an extension of the CakePHP InputHelper. It can be used for loading cloudinary_js, presenting images, creating forms with image inputs and more.
Setup
You can load CloudinaryHelper using two methods -
Controller/PhotosController.php:
[...]
class PhotosController extends AppController {
// Replace the FormHelper with CloudinaryHelper (recommended - accessible as $this->Form)
public $helpers = array('Html', 'Form' => array('className' => 'CloudinaryCake.Cloudinary'));
// Add CloudinaryHelper in addition to the default FormHelper (accessible as $this->Cloudinary instead of $this->Form)
//public $helpers = array('Html', 'Form', 'CloudinaryCake.Cloudinary');
[...]
}
Usage
You then can use it in any view of the controller:
View/Layouts/default.ctp:
[...]
<head>
[...]
# Include cloudinary_js dependencies (requires jQuery)
echo $this->Form->cloudinary_includes();
# Setup cloudinary_js using the current cloudinary_php configuration
echo cloudinary_js_config();
[...]
</head>
[...]
View/Photos/add.ctp:
[...]
<span><?php echo __('Current Photo:'); ?></span>
<?php echo $this->Form->cl_image_tag($photo['Photo']['cloudinaryIdentifier'],
array("width" => 60, "height" => 60, "crop" => "thumb", "gravity" => "face")); ?>
<?php echo $this->Form->create('Photo', array('type' => 'file')); ?>
<legend><?php echo __('Edit Photo'); ?></legend>
<?php
echo $this->Form->input('id');
# Backend upload:
echo $this->Form->input('cloudinaryIdentifier');
# Direct upload:
#echo $this->Form->input('cloudinaryIdentifier', array("type" => "direct_upload"));
?>
<?php echo $this->Form->end(__('Submit')); ?>
[...]
cloudinary/cloudinary_cake_php 适用场景与选型建议
cloudinary/cloudinary_cake_php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 137 次下载、GitHub Stars 达 2, 最近一次更新时间为 2014 年 01 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sdk」 「cloud」 「cdn」 「cloudinary」 「image management」 「cake php」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cloudinary/cloudinary_cake_php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cloudinary/cloudinary_cake_php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cloudinary/cloudinary_cake_php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
UCloud Resource (Cloud) Storage SDK for PHP
The flysystem adapter for yandex disk rest api.
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
非官方云小票机SDK,支持飞鹅云,芯烨云,易联云,快递100,映美云,中午云,佳博云,优声云,365智能云打印等
统计信息
- 总下载量: 137
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-01-21