ElementsCMS.php
The ElementsCMS class is a PHP-based content management system that provides functionality for managing CMS collections and items. It serves as the main entry point for interacting with content stored
Overview
The ElementsCMS class manages the base path for content storage and provides methods to create collections, load items, and manage configuration options.
Constructor
__construct(string $basePath, array $options = [])
__construct(string $basePath, array $options = [])
Creates a new instance of ElementsCMS.Parameters:
$basePath (string)
: The base path for the CMS content storage$options (array, optional)
: Additional configuration options for the CMS
Static Methods
make(string $basePath, array $options = []): ElementsCMS
make(string $basePath, array $options = []): ElementsCMS
Static factory method that creates a new instance of ElementsCMS.Parameters:
$basePath (string): The base path for the CMS content storage
$options (array, optional): Additional configuration options for the CMS
Returns: ElementsCMS instance
Configuration Methods
basePath(): string
basePath(): string
Returns: The base path as a string
options(): array
options(): array
Returns: Array of all options
option(string $key, $default = null): mixed
option(string $key, $default = null): mixed
Returns: The option value or default value
Parameters:
$key (string)
: The option key to retrieve$default (mixed, optional)
: Default value returned if the option is not set
setOption(string $key, $value): void
setOption(string $key, $value): void
Sets an option value.
$key (string)
: The option key to set$value (mixed)
: The value to set
Content Management Methods
collection(string $path, array $options = []): ElementsCMSCollection
collection(string $path, array $options = []): ElementsCMSCollection
Creates a new collection instance.Parameters:
$path (string): The path for the collection (relative to base path)
$options (array, optional): Additional options for the collection
Returns: ElementsCMSCollection instance
item(string $collectionPath, string $slug): ?ElementsCMSItem
item(string $collectionPath, string $slug): ?ElementsCMSItem
Loads a specific item from a collection.Parameters:
$collectionPath (string)
: The path of the collection$slug (string)
: The slug/filename of the item (without .md extension)
Returns: ElementsCMSItem instance or null if not found
Usage Examples
Basic Setup
Working with Collections
Loading Individual Items
Managing Configuration
Dependencies
This class requires the following files:
ElementsCMSCollection.php
ElementsCMSItem.php
Make sure these files are available in the same directory as the ElementsCMS class.
File Structure
The CMS expects content to be organized in the following structure:
cms-base-path/
collection-name/
item-slug.md
another-item.md
another-collection/
item1.md
item2.md
Items must be in Markdown files (.md extension) within collection directories.
Last updated
Was this helpful?