/redaxo-core:redaxo-addon-developmentfrom redaxo-core
Guides building and maintaining custom REDAXO addons: package.yml, boot.php, install/update/uninstall, lang files, fragments, backend pages, assets pipeline, cache-busting, and Composer dependencies.
Ships in redaxo-core. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Addons live under redaxo/src/addons/<addon_name>/. Every addon must have a package.yml; everything else is optional but follows conventions.
redaxo/src/addons/my_addon/
├── package.yml # Manifest – required
├── boot.php # Runs on every request after the addon is enabled
├── install.php # Runs once on install (DB schema, defaults)
├── uninstall.php # Runs on uninstall (clean up)
├── update.php # Runs on version upgrade
├── lang/
│ ├── de_de.lang
│ └── en_gb.lang
├── pages/ # Backend pages (one PHP file per subpage)
├── fragments/ # Reusable view fragments
├── lib/ # Your PHP classes (autoloaded)
├── functions/ # Procedural helpers (manually included)
└── assets/ # Public files (mirrored to assets/addons/my_addon/)
package: my_addon
version: '1.0.0'
author: 'Your Name'
supportpage: https://example.com
requires:
redaxo: '^5.18'
php: '>=8.1'
# Optional: addons your addon needs to be installed
requires_addons:
yform: '^4.0'
# Backend page registration
page:
title: 'My Addon'
icon: rex-icon fa-cube
perm: my_addon[]
subpages:
list:
title: 'List'
settings:
title: 'Settings'
perm: my_addon[settings]
# Default config values (read via $addon->getConfig('key'))
default_config:
items_per_page: 25
feature_enabled: 0
The perm: my_addon[] line creates a permission you can grant to user roles in the backend. my_addon[] = the addon as a whole; my_addon[settings] = a fine-grained permission.
Runs on every request once the addon is enabled. Register extension points and load helpers here.
<?php
$addon = rex_addon::get('my_addon');
// Vendor dependencies (composer.json + vendor/ in your addon) are auto-loaded
// by REDAXO. No manual `require __DIR__ . '/vendor/autoload.php'` needed.
// Note: this only works once the addon is INSTALLED — pre-install code that
// touches vendor/ classes will silently no-op.
// fragments/, lib/ and vendor/ are registered by the core for every installed
// package – no rex_fragment::addDirectory() or autoloader setup needed here.
if (rex::isBackend() && rex::getUser()) {
rex_view::addCssFile($addon->getAssetsUrl('backend.css'));
}
// Hook into the system
rex_extension::register('OUTPUT_FILTER', [my_addon_filter::class, 'apply']);
// Optional: include procedural helpers
require_once __DIR__ . '/functions/helpers.php';
$this inside boot.php also refers to the rex_addon instance, so $this->getAssetsUrl(...) works the same as $addon->getAssetsUrl(...).
Classes under lib/ are autoloaded automatically: lib/my_addon_filter.php → class my_addon_filter. Namespaces work too – rex_autoload parses namespace declarations (core/lib/autoload.php), so PSR-4-style subdirectories need no Composer: lib/Acme/View/Table.php with namespace Acme\View; class Table. Templates and slices have no use context; call such classes fully qualified there (\Acme\Lead::find()).
Throw a rex_functional_exception to abort with a user-visible error. Use rex_sql_table::ensure() for idempotent schema changes.
<?php
// install.php
rex_sql_table::get(rex::getTable('my_addon_items'))
->ensurePrimaryIdColumn()
->ensureColumn(new rex_sql_column('title', 'varchar(255)', false, ''))
->ensureColumn(new rex_sql_column('data', 'json', false))
->ensureColumn(new rex_sql_column('created_at', 'datetime', false))
->ensureIndex(new rex_sql_index('title', ['title'], rex_sql_index::UNIQUE))
->ensure();
// Set defaults
rex_config::set('my_addon', 'items_per_page', 25);
<?php
// uninstall.php
rex_sql_table::get(rex::getTable('my_addon_items'))->drop();
rex_config::removeNamespace('my_addon');
<?php
// update.php – runs after the new files are in place
$installed = rex_addon::get('my_addon')->getVersion();
if (rex_version::compare($installed, '1.1.0', '<')) {
rex_sql_table::get(rex::getTable('my_addon_items'))
->ensureColumn(new rex_sql_column('priority', 'int', false, '0'))
->ensure();
}
Inside update.php, getVersion() still returns the version before the update – the core (install addon and package:run-update-script) writes the new version only afterwards.
When a new option should be on for new sites but must not change existing ones, one default is not enough. Many addons start update.php with require __DIR__ . '/install.php' so schema code lives in one place; then the install defaults run on every update as well and !hasConfig() is true there too. Set the default for new installs in install.php and restore the old behaviour for upgrades in update.php, which runs afterwards and therefore wins:
// install.php
if (!$this->hasConfig('new_option')) {
$this->setConfig('new_option', false); // new installs
}
// update.php – getVersion() is still the old version here
if (rex_version::compare($this->getVersion(), '<last released version>', '<=')) {
$this->setConfig('new_option', true); // existing installs keep the old behaviour
}
The condition must name the last released version, not the upcoming one, otherwise every later update overwrites the user's own setting. Test the comparison against a few old and new version strings before shipping – a wrong operator silently flips behaviour on every existing site.
REDAXO does not serve files from src/addons/<addon>/assets/ directly. On install, those files are copied to the public path /assets/addons/<addon>/. Editing source files does not update the public version.
After editing any file in assets/:
echo "y" | redaxo/bin/console package:install my_addon
This re-syncs assets and re-runs install.php (which is why install.php must be idempotent). Always use this command instead of manually copying files.
Always append ?v=<version> to asset URLs in fragments / templates / backend pages so browsers don't serve stale JS/CSS:
<script src="<?= $addon->getAssetsUrl('script.js') ?>?v=<?= $addon->getVersion() ?>"></script>
In boot.php for backend assets:
rex_view::addCssFile($addon->getAssetsUrl('backend.css') . '?v=' . $addon->getVersion());
rex_view::addJsFile($addon->getAssetsUrl('backend.js') . '?v=' . $addon->getVersion());
// Save
rex_config::set('my_addon', 'key', $value);
// Read
$value = rex_addon::get('my_addon')->getConfig('key');
// Defaults via package.yml `default_config:` block (see above)
Unchecked checkboxes don't send a value, so the post-handler must coerce to int:
// pages/config.php
$addon = rex_addon::get('my_addon');
if (rex_post('save', 'bool')) {
$addon->setConfig('feature_enabled', rex_post('feature_enabled', 'int', 0));
echo rex_view::success('Settings saved.');
}
// Form
'<input type="checkbox" name="feature_enabled" value="1"
' . ($addon->getConfig('feature_enabled') ? 'checked' : '') . ' />';
// In package.yml default_config use 0/1, not true/false
pages/<subpage>.php)Each subpage from package.yml resolves to pages/<subpage>.php. The file outputs the page body; REDAXO wraps the chrome.
<?php
$content = '<fieldset><legend>Settings</legend>';
// ... form HTML ...
$content .= '</fieldset>';
$fragment = new rex_fragment();
$fragment->setVar('title', rex_i18n::msg('my_addon_title'), false);
$fragment->setVar('body', $content, false);
$fragment->setVar('buttons', $buttons ?? '', false);
echo $fragment->parse('core/page/section.php');
Use rex_be_controller::getCurrentPagePart(N) to inspect the current subpage path if you need conditional logic.
pages/index.php dispatcher (required for top-level page: with subpages)When package.yml uses the singular page: key with subpages, REDAXO requires a pages/index.php file for the main entry. Without it the page errors out with:
Package "my_addon": the page path "pages/index.php" neither exists as standalone path nor as package subpath ".../pages/index.php"
The convention (used by core addons like cronjob and backup) is a thin dispatcher that renders the page title once and includes the active subpage file:
<?php
// pages/index.php
echo rex_view::title($this->i18n('title'));
rex_be_controller::includeCurrentPageSubPath();
The subpage files (pages/list.php, pages/settings.php) then render only their body — calling rex_view::title() in a subpage when the dispatcher already does prints the title twice.
pages: (plural) with dot-notation filesUse the plural pages: key to mount additional entries under existing paths (e.g. into REDAXO's system menu), separately from your main page: entry:
pages:
system/log/my_addon:
title: 'My Addon Log'
perm: admin[]
Mounted page files use dot-notation matching the path: slashes become dots, so system/log/my_addon → pages/system.log.my_addon.php. This naming only applies to the plural pages: form — plain pages/<subpage>.php is still correct for subpages of your own top-level page:.
my_addon_title = My Addon
my_addon_item_saved = Item “{0}” has been saved.
echo rex_i18n::msg('my_addon_title');
echo rex_i18n::msg('my_addon_item_saved', $title); // {0} replaced
Always prefix every key with the addon name to avoid collisions.
Addons can ship their own composer.json + vendor/ directory. REDAXO autoloads vendor classes on install — no manual require needed.
vendor/ — changes get lost on composer update.rex_* class nameREDAXO's autoloader resolves classes in lib/ by filename: lib/rex_foo.php → class rex_foo. A drop-in single-file library that ships as e.g. class QRencode (no rex_* prefix, no composer.json) won't be picked up — neither by the REDAXO autoloader nor by the Composer fallback.
Pattern: wrap it in a rex_* class and require_once the file from inside the wrapper. The wrapper is autoloaded on first reference; the wrapped file is included only when actually needed.
lib/rex_qr_wrapper.php // class rex_qr_wrapper — autoloaded
lib/phpqrcode.php // class QRencode — NOT autoloaded
class rex_qr_wrapper
{
public static function encode(string $data): array
{
require_once __DIR__ . '/phpqrcode.php';
return QRencode::factory(QR_ECLEVEL_H, 1, 0)->encode($data);
}
}
Calling code only ever touches rex_qr_wrapper, never the raw library. Same trick works for any non-namespaced single-file lib you'd otherwise be tempted to require from random places.
When building a widget that gets embedded on third-party sites:
localStorage (no cookies needed for cross-domain).<script src=".../widget.js?v=2.3.1">.Edited source assets but didn't reinstall → old version served from /assets/addons/.
No cache-busting on asset URLs → browser serves stale JS/CSS.
Raw SQL queries instead of rex_sql API → SQL injection risk, no table prefix handling.
Missing $published = true on rex_api_function class → 403 from frontend.
Hardcoded API keys → use rex_config instead.
Not using rex::getTable() → missing table prefix breaks multi-instance setups.
Registering fragments/ by hand in boot.php – unnecessary: rex_package::enlist() already calls rex_fragment::addDirectory() for every installed package (core/lib/packages/package.php), just as it adds lib/ and vendor/ to the autoloader. Call addDirectory() only for a directory outside the addon's fragments/.
Missing exit after rex_response::sendJson() → REDAXO appends HTML to JSON.
Inline <style> or <script> tags → blocked by CSP. Always external files via rex_view::addCssFile() / rex_view::addJsFile().
Top-level page: with subpages but no pages/index.php → REDAXO errors on the main entry ("page path ... neither exists ..."). Add a dispatcher (echo rex_view::title(...); rex_be_controller::includeCurrentPageSubPath();).
Putting non-idempotent code in install.php without checks – the user may re-install.
Hardcoding asset paths instead of rex_url::addonAssets() – breaks subdirectory deployments.
Skipping perm: declarations – any backend user can then access the page.
Backend download links broken by PJAX – the backend uses PJAX, which intercepts <a href> clicks and loads the response into the current page instead of triggering a download. rex_api_function returning binary data doesn't help (REDAXO expects a rex_api_result object, not raw output), and target="_blank" is unreliable across PJAX configurations. For small payloads (SVG, CSV, generated text) the cleanest fix is to inline the data as a data: URL on the link and set download="filename.ext" — no server round-trip, PJAX leaves it alone:
Validating a redirect target with parse_url($t, PHP_URL_HOST) alone – javascript:alert(1) and data:… have no host and pass a "no host, so it's relative" check. Accept a relative target only when it starts with a single / and has no scheme: str_starts_with($t, '/') && !str_starts_with($t, '//') && null === parse_url($t, PHP_URL_SCHEME).
Expecting the developer addon to version slice content – it syncs templates, modules and actions to disk; rex_article_slice rows stay in the database and need their own migration or deploy path.
$svg = '<svg ...>...</svg>';
$href = 'data:image/svg+xml;base64,' . base64_encode($svg);
echo '<a href="' . rex_escape($href, 'html_attr') . '" download="export.svg" class="btn btn-xs">SVG</a>';
For larger payloads, render a standalone PHP entry point outside the backend page tree (or use a rex_api_function that hands back a rex_api_result with a redirect to a streaming endpoint).
// Log exceptions (preferred way)
rex_logger::logException(new rex_exception('Something went wrong'));
rex_logger::logException($exception);
// logError requires 4 params; prefer logException
// rex_logger::logError($errno, $errstr, $errfile, $errline);
// Verbose error output for developers
if (rex::isDebugMode()) {
// ...
}
// Dump (uses Symfony VarDumper if debug addon is active)
dump($variable);
For CLI/diagnostic tasks, see the redaxo-console-commands skill — never write standalone bootstrap scripts under bin/.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub friendsofredaxo/claude-marketplace --plugin redaxo-core11 skills in this plugin
/redaxo-api-functionsBuilding HTTP/AJAX endpoints in REDAXO using rex_api_function – the lib/ class location, naming convention, $published flag for frontend access, JSON responses, CORS for cross-domain widgets, and the rex-api-call URL. Use when the user adds an AJAX/HTTP endpoint to a custom addon, builds a JSON API for a frontend widget, or asks how to expose data via /index.php?rex-api-call=. Distinct from the FriendsOfRedaxo/api addon (covered by the redaxo-api-addon plugin)./redaxo-architectureREDAXO project structure, request lifecycle, and core classes. Use when the user works on a REDAXO codebase, mentions REDAXO directory layout, asks about rex_addon/rex_config/rex_path/rex_url/rex_clang/rex_request, or when files under redaxo/src/, redaxo/data/, or redaxo/cache/ appear in the conversation./redaxo-console-commandsOther plugins' skills for the same job