API Reference
Key classes and helper functions available in Cainty.
Helper Functions
| Function | Returns | Description |
|---|---|---|
cainty_url($path = '') | string | Full URL for a path |
cainty_admin_url($path = '') | string | Admin panel URL |
cainty_asset($path) | string | Theme asset URL with cache-busting |
cainty_config($key, $default) | string | Get .env config value |
cainty_is_admin() | bool | Check if user is admin |
cainty_current_site() | array | Get current site settings |
cainty_site_id() | int | Get current site ID |
cainty_verify_csrf() | bool | Verify CSRF token |
e($string) | string | HTML-escape a string |
Core Classes
Cainty\Database\Database
PDO database wrapper (static singleton):
use Cainty\Database\Database;
$pdo = Database::get();
$stmt = $pdo->prepare("SELECT * FROM posts WHERE post_id = ?");
$stmt->execute([$id]);
$post = $stmt->fetch();
Cainty\Content\Post
Static methods for post operations:
use Cainty\Content\Post;
// Get published posts
$posts = Post::getPublished($siteId, $limit, $offset);
$count = Post::countPublished($siteId);
// Get single post by slug
$post = Post::getBySlug($slug, $siteId);
Cainty\Content\Category
use Cainty\Content\Category;
$categories = Category::getAll($siteId);
$category = Category::getBySlug($slug, $siteId);
Cainty\Content\Tag
use Cainty\Content\Tag;
$tags = Tag::getAll($siteId);
$tags = Tag::getForPost($postId);
Cainty\Content\Media
use Cainty\Content\Media;
$files = Media::getAll($siteId, $limit, $offset);
$file = Media::getById($id);
Cainty\Themes\ThemeLoader
use Cainty\Themes\ThemeLoader;
$theme = new ThemeLoader();
$theme->render('home', ['posts' => $posts]);
$theme->renderPart('header', compact('site'));
Cainty\Plugins\Hook
use Cainty\Plugins\Hook;
// Actions
Hook::on('event_name', $callback, $priority);
Hook::fire('event_name');
// Filters
Hook::filter('filter_name', $callback, $priority);
$result = Hook::apply('filter_name', $value);
Cainty\Shortcodes\ShortcodeEngine
use Cainty\Shortcodes\ShortcodeEngine;
ShortcodeEngine::register('tag', function ($attrs) {
return 'output HTML';
});
$html = ShortcodeEngine::process($content);
Cainty\Routing\Router
// Route definitions (in core/routes.php)
$router->get('/path', [Controller::class, 'method']);
$router->post('/path', [Controller::class, 'method']);
$router->group('/prefix', function ($router) {
$router->get('/sub', [Controller::class, 'method']);
}, ['middleware_name']);