Project 8: your first extension
Extensions are how Exponential is extended without changing the kernel. In this project you build the smallest working extension, a page that greets a visitor by name, then make it safe and keep it in Git. The steps follow Extensions, section 6.
Contents
At a glance
| Level | Intermediate |
| Time | About 4 hours |
| Paths | Developer |
| Prerequisites | PHP basics; a terminal; project 3; Using Git as a student |
Goal
An extension with your own name (for example studyhello) that serves /hello/world/<name>, shows the name escaped
inside your site's layout, is listed under Setup > Extensions with its version, is protected by a policy, and
lives in its own Git repository.
Before you start
- Read Extensions, sections 1, 4 and 6.1, and What an extension is.
- Pick a name that is yours: lower case, letters, digits and underscores. The guide uses
myhello.
Tasks
Create the folders
extension/<name>/settings,modules/helloanddesign/standard/templates/hello.Write
ezinfo.phpandextension.xmlwith the same version (0.1.0), your name in the copyright line, and "GNU General Public License v2.0 (or any later version)" as the license.Write the settings:
settings/module.ini.append.phpwithExtensionRepositories[]=<name>under[ModuleSettings], andsettings/design.ini.append.phpwithDesignExtensions[]=<name>under[ExtensionSettings].Write the module and the view:
modules/hello/module.phpwith one viewworldthat takes the parameterName, andmodules/hello/world.phpthat passes the name to the template and returns$Result.Write the template
design/standard/templates/hello/world.tpl, printing the name with{$name|wash}.Check the PHP:
php -lon each PHP file. Expected:No syntax errors detected in <file>.Switch it on and refresh:
php bin/php/console exp:ini add 'site.ini/ExtensionSettings/ActiveExtensions[]' <name> global --allow-root-user php bin/php/ezpgenerateautoloads.php -e php bin/php/ezcache.php --clear-all --allow-root-userOpen
/hello/world/Adaon your site. Expected: Hello, Ada inside your site's layout, and Setup > Extensions lists your extension with version 0.1.0.Try to break it. Open
/hello/world/<b>Ada</b>(URL encoded if needed). The name must be shown as text, not as bold markup. Explain why.Protect the view. A view without a
'functions'entry has no access control: anyone who can reach the site can open it. Declare a function ($FunctionList['read'] = array();inmodule.php,'functions' => array( 'read' )on the view) and grant it in Users > Roles and policies to a role. Check as anonymous visitor and as a user with the role (Extensions).Commit the extension to its own Git repository, with a commit subject such as
Added: The hello world view.
Hand in
- The repository (or an archive of it) with every file of the extension.
- Screenshots: the greeting page; Setup > Extensions with your extension; the denied page for a visitor without the policy.
- The output of
php -lfor each PHP file. - A short report: what each file does, and why the policy matters.
Rubric
Score the four common criteria of Grading your own work, and these checks (8):
- The extension name is the learner's own, lower case.
ezinfo.phpandextension.xmlcarry the same version and the license.- Every PHP file passes
php -l. - The extension was switched on with a settings override, not by editing
settings/site.ini. - The greeting works and the name is escaped.
- The view is protected by a function and a policy, shown for both cases.
- The extension is in its own Git repository with readable commit subjects.
- No kernel file was changed.
Stretch goals
- Generate a module with the RAD wizard (
/setup/moduleextension) and compare its files with yours (Extensions). Note: the wizards list every file before writing and never overwrite an existing extension. - Add a setting of your own in
settings/<name>.iniand read it witheZINI::instance( '<name>.ini' )(Extensions). - Add a translation of the greeting (Extensions, section 6.4).
- Publish it on GitHub as your own project (Contribute extensions back). Your own extension is not covered by the CLA (The CLA for students).
Related pages
- Study projects: overview
- Extensions
- Learning path: developer
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.