Cookbook
Each page of the cookbook builds one thing from start to finish: the files you write, the settings that switch them on, the command that checks them and what goes wrong most often. The pages build on each other through one example extension, expexample, so the code of one page is reused by the next. Read An extension skeleton first if you have never made an extension.
Every example was written from the code of this release and checked where that is cheap: PHP files with php -l,
templates with bin/php/eztemplatecheck.php, XML files with xmllint. Each page says what was checked and lists the
source files it was derived from. Nothing here was run against a production database; try every example on a copy of
your site first.
The recipes
| Task | Page | What it touches |
|---|---|---|
| Start an extension of your own | An extension skeleton | extension/<name>/, ezinfo.php, extension.xml, composer.json, ActiveExtensions[], the autoload array |
| Create a content class | Create a content class | Setup > Classes, or eZContentClass and eZContentClassAttribute in a script |
| Change how one page or class looks | A template override | override.ini.append.php, design/<design>/override/templates/, the override cache |
| Add a template operator | A custom template operator | autoloads/eztemplateautoload.php, [TemplateSettings] ExtensionAutoloadPath[] |
| Add a page with its own address and policy | A custom module and view | modules/<module>/module.php, module.ini [ModuleSettings], $FunctionList, Roles and policies |
| Store a new kind of field | A custom datatype | datatypes/<type>/<type>type.php, content.ini [DataTypeSettings], the datatype templates |
| Run code when content is published | A workflow event | eventtypes/event/<type>/, workflow.ini [EventSettings], Setup > Workflows and Triggers |
| Run code on a schedule | A cronjob | cronjobs/, cronjob.ini [CronjobSettings] and [CronjobPart-<part>], the crontab |
| Read content as JSON from a script or the browser | REST and JSON calls | ezjscore server functions, ezjscore.ini [ezjscServer_<name>], the REST API below /api/ |
| Serve several sites from one installation | Several sites: siteaccesses | site.ini [SiteAccessSettings], settings/siteaccess/<name>/, VarDir, CacheVarDir |
| Translate the texts of an extension | Translations | translations/<locale>/translation.ts, ezpI18n::tr(), |i18n, TranslationExtensions[] |
| Make pages fast and keep them current | Caching | the view cache, cache-block, ezcache.php, Velocity's response cache |
| Put a PHP change live | Deploying with Velocity | exp:velocity deploy and its steps |
| Turn what you configure into a migration | Record an administrator session | exp:migration:record:*, Setup > Migrations > Recording, exp:migration:generate --from-recording |
The example extension at a glance
extension/expexample/
├── ezinfo.php what the extension is (Setup > About, Setup > Extensions)
├── extension.xml the same, read first; the same version number
├── composer.json when it is installed with Composer
├── autoloads/ template operators (custom-template-operator.md)
├── classes/ classes found through the autoload array (rest-json-fetch.md)
├── cronjobs/ cronjob scripts (cronjob.md)
├── datatypes/expcolor/ a datatype (custom-datatype.md)
├── eventtypes/event/explogpublish/ a workflow event (workflow-event.md)
├── modules/expexample/ a module with two views (custom-module-view.md)
├── design/standard/templates/ its templates; design/standard/javascript/ its scripts
├── translations/ger-DE/ its German texts (translations.md)
└── settings/ *.ini.append.php: what switches each part onThe names follow the project's convention for new code: the extension, its module and its classes start with exp
(expexample, expExample...), never with ez.
Reference material
The cookbook shows how; the reference areas list what exists, generated from the code:
- Template operators and fetch functions
- Module views and policy functions
- INI settings, datatypes, workflow events, cronjob parts
- Commands and extension points
The coding rules and the pattern catalogue (how code, templates and documentation are written in this project) are in the standards; the cookbook follows them and does not repeat them.
Related pages
- Examples: every example area, including the web server configurations.
- Extensions: find, install, configure, build and release
- Templates and design
- RAD tools: the wizards that write most of these skeletons for you.
- Free documentation: this page is free to copy, translate and improve.