Views can be used to create both web pages and HTML mail, while maintaining a division between the logic and layout of your page. This crucial split makes updates easier and readability of your code. When working with Graphics Designers this also allows an area for pure HTML which can be linked quickly with the logic code behind, allowing PHP coding in a large muti-discipline team.
Views for the application are added into the folder “framework/application/view” and are called from controllers, this simple file can contain any type of code. Let’s start by showing an example.
Type the following code into framework/application/view/index.php
Let’s try and load this in a controller:
You can see that he Router::loadView function actually includes the framework/application/view/index.php (basically navigates to the folder and adds a PHP on the end), and displays it in the controller. You can also have a folder structure in the view folder, for example Router::loadView(“x/y/z/view”) would load framework/application/view/x/y/z/view.php
Variables are easy to pass to views too:
Now try loading http://localhost/, http://localhost/ivebeenlinuxed or http://localhost/test – Clever eh!
Advantages to using views?