Components & Helpers API Reference
This document provides documentation for components and helpers used throughout the Yoneily system.Components
Components are reusable pieces of controller logic that can be shared across multiple controllers.PasswordHelperComponent
A utility component for generating random passwords. Location:app/controllers/components/password_helper.php
Methods
generatePassword($length = 8)
Generates a random password from a predefined set of characters.Length of the password to generate
0123456789bcdfghjkmnpqrstvwxyz
Algorithm:
- Uses
mt_rand()for random character selection - Ensures no duplicate characters in the password
- Continues until desired length is reached
string - The generated password
Example Usage:
- Password recovery functionality
- Initial password generation for new users
- Temporary password creation
phpThumb Component
Image manipulation and thumbnail generation component. Location:app/controllers/components/phpThumb.php
Note: This is a third-party library (27,563 bytes) used throughout the application for advanced image processing.
Features:
- Image resizing
- Thumbnail generation
- Format conversion
- Quality adjustment
Helpers
Helpers are used in views to format and present data to users.ImageHelper
Automatically resizes images and generates properly formatted HTML image tags. Location:app/views/helpers/image.phpVersion: 1.1
Authors: Josh Hundley, Jorge Orpinel
Properties
Methods
resize(width, aspect = true, return = false)
Automatically resizes an image and returns a formatted IMG tag.Path to the image file, relative to the
webroot/img/ directoryWidth of the returned image in pixels
Height of the returned image in pixels
Whether to maintain aspect ratio during resize
Array of HTML attributes for the
<img> tag (e.g., ['alt' => 'Description', 'class' => 'thumbnail'])Whether to return the value or output it directly
mixed - Either string HTML or echoes the value
Supported Image Types:
- GIF
- JPEG
- PNG
- SWF
- PSD
- WBMP
-
Automatic Caching
- Checks if resized image already exists in cache
- Verifies cache is up-to-date with source file
- Only regenerates if needed
-
Aspect Ratio Preservation
- Automatically adjusts dimensions when
$aspect = true - Calculates proper width or height to maintain proportions
- Prevents image distortion
- Automatically adjusts dimensions when
-
Smart Resizing
- Uses
imagecreatetruecolor()andimagecopyresampled()for high quality - Falls back to
imagecreate()andimagecopyresized()if needed - Handles both upscaling and downscaling
- Uses
-
Cache Management
- Stores resized images in
uploads/resized/directory - Names cached files as
{width}x{height}_{originalname} - Automatically updates cache when source file changes
- Stores resized images in
-
Path Resolution:
-
Aspect Ratio Calculation:
-
Cache File Naming:
-
Freshness Check:
- Only processes images when cache is missing or outdated
- Reuses cached images for repeat requests
- Efficient dimension calculations to minimize processing
- Returns
nullif source image doesn’t exist - Validates image with
getimagesize() - Handles missing cache directory gracefully
-
Product Thumbnails:
-
Responsive Images:
-
Gallery Previews:
Integration with SimpleImage
The controllers use theSimpleImage class (imported from Vendor) for additional image processing:
SimpleImage Usage in Controllers
Common Operations:1. Loading Image
2. Resizing by Width
3. Resizing by Height
4. Saving Processed Image
Standard Image Sizes
Promotions (Promos)
- Thumbnail: 450×280 pixels
- Slider: 779×280 pixels
Products (Galleries)
- Thumbnail: 124×124 pixels
- Normal: 600×480 pixels
Stores (Locales)
- Thumbnail: 96×72 pixels
- Slider: 600×480 pixels
- Location: 600×480 pixels
Videos
- Thumbnail: 96×72 pixels
Helper Integration Examples
Using ImageHelper with Database Fields
Dynamic Sizing Based on Context
Best Practices
For Components
-
PasswordHelper Usage:
-
Error Handling:
For Helpers
-
Always Provide Alt Text:
-
Consistent Sizing:
-
Performance Considerations:
Security Considerations
PasswordHelper
- Generated passwords exclude ambiguous characters (0/O, 1/l, etc.)
- Uses cryptographically strong
mt_rand() - Ensures uniqueness within generated password
ImageHelper
- Validates file existence before processing
- Uses
getimagesize()to verify image integrity - Sanitizes file paths to prevent directory traversal
- Only processes whitelisted image types