| description | 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 |
|---|
The ElementsCMS class manages the base path for content storage and provides methods to create collections, load items, and manage configuration 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
$cms = new ElementsCMS('/path/to/content', ['debug' => true]);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
$cms = ElementsCMS::make('/path/to/cms_data');Returns: The base path as a string
$path = $cms->basePath(); // Returns '/path/to/content'Returns: Array of all options
$allOptions = $cms->options();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
$debug = $cms->option('debug', false);
$theme = $cms->option('theme', 'default');Sets an option value.
$key (string): The option key to set$value (mixed): The value to set
$cms->setOption('debug', true);
$cms->setOption('cache_enabled', false);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
$articles = $cms->collection('articles', ['sort' => 'date']);
$projects = $cms->collection('projects');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
$blogPost = $cms->item('blog', 'my-first-post');
$aboutPage = $cms->item('pages', 'about');<?php
require_once '/path/to/ElementsCMS.php';
$cms = ElementsCMS::make(
'/var/www/cms_data',
['debug' => true, 'cache_ttl' => 3600]
);// Create a blog collection
$blog = $cms->collection('blog', ['sort' => 'date_desc']);
// Create a pages collection
$pages = $cms->collection('pages');// Load a specific blog post
$post = $cms->item('blog/introduction-to-cms');
// Load a page
$homepage = $cms->item('pages/home');// Get configuration
$debugMode = $cms->option('debug', false);
$cacheEnabled = $cms->option('cache_enabled', true);
// Set configuration
$cms->setOption('theme', 'custom');
$cms->setOption('max_items_per_page', 10);This class requires the following files:
- ElementsCMSCollection.php
- ElementsCMSItem.php
Make sure these files are available in the same directory as the ElementsCMS class.
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
- collection-name/
Items must be in Markdown files (.md extension) within collection directories.