Lesson 6.1: How modules and views work
Every page that is not a content page is a module view: /user/login, /setup/cache, /content/edit/12. Even
content pages are the view content/view. This lesson explains how an address becomes a call to a view, what a
module.php declares, and how a view hands its HTML to the pagelayout. It prepares lesson 6.2, where learners write
a view of their own.
At a glance
| Course | Developers |
| Module | Module 6: Modules and views |
| Duration | 45 minutes (25 presenting, 20 exercise) |
| Level | Intermediate |
| Audience | Developers |
| Prerequisites | Lesson 1.1 and Module 5 |
Learning objectives
After this lesson, learners can:
- split an address into siteaccess, module, view, ordered parameters and unordered parameters;
- read
$ViewListentries in amodule.php:script,params,unordered_params,functions,single_post_actions; - find the code of a kernel view in
kernel/private/classes/views/<module>/<view>.php; - describe the
$Resultarray a view returns and how the pagelayout shows$module_result.content.
Trainer's notes
How to present it
Sources: Reading the code you already have, technique 2 and Commands, cronjob parts and module views as classes.
An address (4 minutes).
/admin/content/view/full/2/(offset)/20: siteaccessadmin, modulecontent, viewview, ordered parametersfulland2(namedViewModeandNodeIDinmodule.php), unordered parameteroffsetwith the value20.module.php(6 minutes). Show$ViewList['view']inkernel/content/module.php:$ViewList['view'] = array( 'functions' => array( 'read' ), 'default_navigation_part' => 'ezcontentnavigationpart', 'script' => 'view.php', 'params' => array( 'ViewMode', 'NodeID' ), 'unordered_params' => array( 'language' => 'Language', 'offset' => 'Offset', ... ) );functionsnames the policy a user needs (content/read);single_post_actionsmaps a pressed button to an action name.$FunctionListat the end lists the policy functions and their limitations.Script or class (4 minutes).
kernel/section/view.phpis one line:return \Exponential\View\Kernel\Section\View::main( __FILE__, get_defined_vars() );. The code moved tokernel/private/classes/views/section/view.php. Extension views can be plain scripts or classes; both work.$Result(4 minutes). A view sets$Result['content'](the HTML, usually from a template) and$Result['path'](the breadcrumb). The pagelayout prints the content with{$module_result.content}.Navigation parts (2 minutes).
default_navigation_partdecides which tab of the administration is highlighted.
Common questions
Where do $Params come from? The module runner fills $Params with the named ordered parameters and
$Params['UserParameters'] with the unordered ones.
Can an extension add a view to a kernel module? Yes, with care: Extension module override explains how an extension provides or overrides views and templates of a module.
Why did kernel views become classes? So they can be replaced and listened to through settings and events without editing kernel files (the specification above).
Pitfalls
- Looking for logic in the one-line entry file. Follow the class name to
kernel/private/classes/views/. - Confusing the module name and the folder. The folder name under
modules/is the module name in the address. - Forgetting the siteaccess part. On a site matched by path, the first part of the address is the siteaccess, not the module.
Hands-on exercise
On the development installation, in a shell.
- Show the
viewentry:grep -n "ViewList\['view'\]" -A10 kernel/content/module.php. - Find the entry for
/user/login:grep -n "ViewList\['login'\]" -A10 kernel/user/module.php. Write down its script, parameters and whether it namesfunctions. - Open the entry file
kernel/user/login.phpand follow the class it calls to its file belowkernel/private/classes/views/. - Count the kernel view classes:
find kernel/private/classes/views -name "*.php" | wc -l. - List the policy functions of the section module:
grep -n "FunctionList\[" kernel/section/module.php. - In the browser, open
/content/view/full/2/(offset)/10on your site and on the administration; note how the siteaccess part differs. - Find where the standard design prints the result (
pagelayout.tplincludespage_mainarea.tpl):grep -rn "module_result.content" design/standard/templates/page_mainarea.tpl. - Write the five parts of the address
/admin/content/view/full/2/(offset)/20on paper.
Expected result
- Step 2: the
loginview with its script and post actions. - Step 3: the learner names the class file, for example
kernel/private/classes/views/user/login.php. - Step 7: the line where the pagelayout prints the view's result.
- Step 8: siteaccess
admin, modulecontent, viewview, parametersfulland2, unorderedoffset=20. - The trainer checks step 8 with the whole group.
Quiz
- In
/content/view/full/2, which part is the view? - Which
$ViewListkey names the policy a user needs for the view? A.scriptB.paramsC.functionsD.default_navigation_part - What does
/(offset)/20become inside a view? - Which key of
$Resultholds the HTML of the view? - Where is the code of the kernel view
section/viewsince Exponential 6?
Answers
view(the module iscontent).- C.
functions, for examplearray( 'read' ). - An unordered parameter:
$Params['UserParameters']['offset'], and$view_parameters.offsetin the templates of content views. $Result['content'].- In
kernel/private/classes/views/section/view.php, classExponential\View\Kernel\Section\View.
Further reading
- Reading the code you already have.
- Commands, cronjob parts and module views as classes.
- Extension module override.
Related pages
- Module 6: Modules and views
- Developers: course overview
- Trainers: start here
- 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.