Download the PHP package bgillieron/yii2-cloudinary without Composer
On this page you can find all versions of the php package bgillieron/yii2-cloudinary. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bgillieron/yii2-cloudinary
More information about bgillieron/yii2-cloudinary
Files in bgillieron/yii2-cloudinary
Package yii2-cloudinary
Short Description A Yii2-friendly wrapper for Cloudinary’s PHP SDK: upload widget, responsive images, and media management.
License MIT
Informations about the package yii2-cloudinary
Yii2Cloudinary
Cloudinary integration for the Yii2 PHP Framework.
This extension provides a Yii2-friendly wrapper around the official Cloudinary PHP SDK, enabling seamless uploads, media management, and responsive image rendering in Yii2 projects.
📁 Project Structure
🛠 Features
- Upload images and files to Cloudinary with a single call
- Automatically configure credentials via Yii component
- Drop-in Upload Widget integration with runtime options
- Responsive image rendering with automatic
srcset - Orientation-aware rendering via image meta
- PhotoSwipe support for lightbox galleries
- Database schema for multilingual media metadata
- Easily relate uploaded media to your own models
- Fully translatable Upload Widget UI
📦 Installation
Install the extension via Composer:
🔧 Configuration
Add the module and component to your Yii2 config:
🧱 Migrations
To create the necessary tables for storing Cloudinary media and metadata, run:
This will create:
cloudinary_mediacloudinary_media_desccloudinary_image_meta
📖 For full details on table structure and purpose, see Cloudinary Media Migrations.
🚀 Media Usage
Uploading Files (Server-Side)
This method:
- Uploads the file to Cloudinary
- Saves the
cloudinary_mediarecord - If
relationKeyis provided and defined in your config, invokes the matching relation handler
🔄 Uploading with Custom Payload
You can pass extra metadata to control how the upload is saved:
customPayloadis forwarded to both the database save and yourrelationSaverMapcallback.- This allows custom logic or model relation setup based on the upload context.
🔁 Saving Upload Result & Creating Relations
When a file is uploaded to Cloudinary, the extension automatically saves a corresponding record in the database (cloudinary_media) — but in most real-world projects, you’ll also want to associate that file with a specific model (like Post, Product, User, etc.).
To keep your application logic clean and flexible, this extension introduces the concept of relation callbacks, defined via the relationSaverMap.
🧠 Why Use relationSaverMap?
- You may need different logic for different upload contexts (e.g. a product image, an avatar, a gallery).
- Each upload (or widget instance) can pass a
relationKeyto identify which logic should run. - You configure these mappings once in your app config — no need to pass closures at runtime.
🗂️ Define Any Number of Relation Handlers
Rendering a Responsive Image
- Generates
<img>tag with optimized Cloudinarysrcset - Optional aspect ratio detection (e.g.
'4:3','1:1') - Orientation-aware layout using image meta (landscape vs portrait)
- Lazy loading and format auto-selection supported
📖 See Render Responsive Image for advanced usage and options.
🖼 Upload Widget & UI
Rendering the Upload Widget
This registers the Cloudinary Upload Widget and binds it to the DOM element with the given ID.
Key behaviors:
- Automatically registers and loads Cloudinary’s JavaScript dependencies
- Uploads files to Cloudinary and sends metadata to your configured
uploadHandlerUrlendpoint, which persists the media and optionally links it using yourrelationSaverMap - If a
relationKeyis passed, it is forwarded to the server to trigger a matching callback from yourrelationSaverMap customPayloadis included in the upload metadata for advanced save logicreloadAfterClosereloads the page when the widget is closed (optional)- You can also pass
textoverrides for localization
🔁 Upload Handler URL
When a file is uploaded via the widget, Cloudinary sends the file to their CDN,
then triggers a callback with metadata that is posted to your app’s upload handler.
By default, this handler is set to:
You can override this in your component config if needed:
This endpoint must match the route defined by your Yii2CloudinaryController::actionUploadHandler()
and is responsible for saving the uploaded media record and executing your relationSaverMap logic.
Only change this if absolutely necessary — overriding it incorrectly will break key functionality of this module.
🌍 Upload Widget Localization
This extension supports:
- Default English UI via embedded translations
- App-level language overrides via
messages/<lang>/uploadWidget.php - Runtime
textoverrides passed touploadWidget()
📖 See Upload Widget Localization for a complete guide.
🖼 Lightbox Support (PhotoSwipe)
Register the ESM Asset Bundle
Initialize in View
📌 ES modules require explicit import and do not auto-run.
⚙️ Advanced Access
SDK Access
This returns the Cloudinary\Cloudinary instance for advanced transformations.
Model Reference
These models support multilingual metadata and responsive rendering:
CloudinaryMediaCloudinaryMediaDescCloudinaryImageMeta
📝 License
MIT License © Brendon Gilliéron