View Controller and Translations

Files

/resources/[language].translations.ini

/controllers/controller.view.php

/views/view.[view].php

Introduction

Wave Framework comes with a View Controller and a translations system that is used to build a website on Wave Framework. This View Controller is entirely optional and can be removed from a system if you plan to implement your own View Controller or simply use Wave Framework for API, without a website.

Translations are stored in an INI file that lists all the translation keywords for all languages - with one translations file per language - and these files are used by View Controller and the Views loaded by the View Controller to display appropriate translations in the views.

You can edit Translations file and View Controller file according to your needs. While default View Controller can easily work for majority of websites, it is recommended to do your tweaks to View Controller HTML template and include your CSS files, JavaScript libraries and set up your basic HTML frame within that Controller.

Dynamic Loading

View Controller generates a basic HTML frame for a View entirely based on what data is returned from Sitemap. Sitemap files include multiple configuration options, among which is the 'view' name as well as two variables 'php-libraries' and 'js-libraries'. If any of the latter two settings were set in Sitemap file for the View that is currently being loaded, then these values - which can be comma-separated - are loaded dynamically by View Controller as libraries.

If you have set 'php-libraries' setting to 'example', then View Controller loads '/resources/libraries/example.php' file. If 'js-libraries' setting is set to 'example', then the script '/resources/libraries/example.js' is also loaded.

On top of loading the dynamic library is that you can also load view-specific JavaScript or PHP scripts. So if you are currently in the view of 'example', then View Controller will also load scripts '/resources/scripts/example.script.php' and '/resources/scripts/example.script.js'. It is also smart enough to unify HTTP requests for such a loading.

If this dynamic-loading behavior needs to be changed by you in any way, then you have the entire access to it in View Controller file itself.

Translations

Translations file is an easy-to-edit file that defines all translation keywords and their values. Since Wave Framework is built upon UTF-8 through and through, it is recommended to make sure your translations file is also in UTF-8 encoding, otherwise various foreign characters will show up wrong on the website.

There is one Translations file per language and the name of the Translations file must match the language keywords listed in your configuration file. If 'en' is one of your languages, then you need an 'en.translations.ini' file in your /resources/ folder.

Wave Framework has an example 'en' language translations file by default in te /resources/ folder and you can edit it according to your needs.

Every row in Translations file is one translation. The key is the keyword that is referred to in the Views when using translations and the value is what the value will be when the View is rendered. For example:

	
	hello-world="Hello Wave"
	

This example means that if 'hello-world' is referred to in a view, then it will be rendered as 'Hello Wave' as per translation. If there was another translation file with a different value to that same keyword - and that language was shown on the web page - then the other value would be shown instead.

Please note that INI files have certain reserved words which throw an error if they are used as keywords for translations. To make sure that you do not encounter these errors, do not use the following as translation keys: null, yes, no, true, false, on, off, none.

View Controller

Wave Framework comes with a single View Controller by default and this View Controller is used to generate the HTML frame and load specific view or number of views within that frame.

This View Controller does a number of things:

It is possible to define multiple View Controllers and use different View Controller methods to load views based on settings in Sitemap file. But by default Wave Framework has only a single View Controller and method.

View Controller is usually modified for each new project in little ways to include all the required resources and build the HTML frame that other views will use across the system. It is a good idea to modify the default View Controller or create a new one based on that View Controller.

Views

Views are stored in /views/ folder in Wave Framework. These views are loaded by View Controller based on the URL that was requested and the view that URL Controller found is requested.

By default there are three views in /views/ folder:

Some of the useful method calls and variables within View file that is extended from Factory class are as follows:

There are other useful methods too and every View has access to entire State, API and Database connections within the system, giving you an entirely free reign. It is also possible for views to load other views and create entire chain of views, which gives you flexibility to design a system in any and every way possible.

It is recommended to visit the example page, http://www.example.com/example/ with the default installation (just replace the domain name with yours), and see what the examples printed in that view display. All of this data can be used to build a website.

There is more information about the methods and features in other feature guide documentation pages.