anax / view
Anax View module, collect and render views.
Installs: 18 633
Dependents: 49
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 2
Open Issues: 1
Requires
- php: ^7.2
- anax/commons: ^2.0.0@alpha
Requires (Dev)
- anax/configure: ^2.0.0@alpha
- anax/di: ^2.0.0@alpha
- phpunit/phpunit: ^7
- dev-master
- v2.0.18
- v2.0.16
- v2.0.15
- v2.0.14
- v2.0.13
- v2.0.12
- v2.0.11
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v2.0.0-beta.14
- v2.0.0-beta.13
- v2.0.0-beta.12
- v2.0.0-beta.11
- v2.0.0-beta.10
- v2.0.0-beta.9
- v2.0.0-beta.8
- v2.0.0-beta.7
- v2.0.0-beta.6
- v2.0.0-beta.5
- v2.0.0-beta.4
- v2.0.0-beta.3
- v2.0.0-beta.2
- v2.0.0-beta.1
- v2.0.0-alpha.8
- v2.0.0-alpha.7
- v2.0.0-alpha.6
- v2.0.0-alpha.5
- v2.0.0-alpha.4
- v2.0.0-alpha.3
- v2.0.0-alpha.2
- v2.0.0-alpha.1
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
This package is auto-updated.
Last update: 2024-11-07 16:36:07 UTC
README
Anax View module to supply a structure of views to a Anax website.
About views, terminology and structure
The views, also known as template files, are pure PHP files and their purpose is to render content onto a html structure to create a web page.
It works like this:
- The content of the webpage is gathered as a collection of views.
- The view collection is created in the router callbacks and controllers.
- A view is a combination of variables (content), commonly known as
$data
, which is supplied to a template file, which is executed and renders the data onto a html structure. - Each view is a small part of html and content and rendered onto the web page.
You can see a sample of views in the directory view/anax/v2
.
Views are rendered in a layout
The views are rendered in an orderd fashion by a structured layout. This layout is in itself a view (template file and data), it is just a view which renders more views.
You can see a sample of an layout view in view/anax/v2/layout
.
The layout views you above have organised each part of the web page as regions. Each view is rendered in a region.
This code shows how a general region is setup in the layout file, and how it renders the views belonging to this region.
<!-- flash --> <?php if (regionHasContent("flash")) : ?> <div class="outer-wrap outer-wrap-flash"> <div class="inner-wrap inner-wrap-flash"> <div class="row"> <div class="region-flash"> <?php renderRegion("flash") ?> </div> </div> </div> </div> <?php endif; ?>
You can optionally add a region, and a sort value, when you add the views to the collection. This is what decides where (region), and in what order the view is rendered.
A template file for the view
A template file is an ordinary PHP-file. Here is the template file anax/v2/article/default
.
<?php namespace Anax\View; /** * Render content within an article. */ // Show incoming variables and view helper functions //echo showEnvironment(get_defined_vars(), get_defined_functions()); // Prepare classes $classes[] = "article"; if (isset($class)) { $classes[] = $class; } ?><article <?= classList($classes) ?>> <?= $content ?> </article>
The namespace makes it possible to access a list of built in view helper functions, for example helper functions to escape output or create urls into the framework or assets.
namespace Anax\View;
The commented section can be uncommented for debugging what helper functions and what variables that are available.
// Show incoming variables and view helper functions //echo showEnvironment(get_defined_vars(), get_defined_functions());
The general idea is then to further prepare content through incoming variables.
// Prepare classes $classes[] = "article"; if (isset($class)) { $classes[] = $class; }
Then finally render the output.
<article <?= classList($classes) ?>> <?= $content ?> </article>
That is the general procedures of a template file.
View helpers
The file View/ViewHelperFunctions
holds the helper functions that eases work in the template files.
Here are some essential helpers.
Review the helper files for details.
Dumb views or fat views
A view can be "dumb" and only recive input from the framework, and render it with the html code.
A view can also be "fat", or perhaps not so "smart", and make calls back into the framework.
The general recomendation is to have dumb views and not make calls back into the framwork.
Type of views
A view can generally render any type of result and is not limited to html only.
License
This software carries a MIT license. See LICENSE.txt for details.
.
..: Copyright (c) 2013 - 2019 Mikael Roos, mos@dbwebb.se