User Rating: 2 / 5

Star ActiveStar ActiveStar InactiveStar InactiveStar Inactive
 

The View, as you might have guessed, is the 'V' in MVC. The View contains code that relates to presentation and presentation logic such as templating and caching. In the controller above we saw the show() method. This is the method that calls the view. The major component in the MindPHP.com MVC is the template class. The template.class.php file contains the class definition. Like the other classes, it has the registry available to it and also contains a __set() method in which template variables may be set and stored.

 

The show method is the engine room of the view. This is the method that loads up the template itseld, and makes the template variables available. Some larger MVC 's will implement a template language that adds a fhurther layer of abstraction from PHP. Added layers means added overhead. Here we stick with the speed of PHP within the template, yet all the logic stays outside. This makes it easy for HTML monkies to create websites without any need to learn PHP or a template language.

 

The template.class.php file looks like this:

<?php
Class Template {
private $registry;
private $vars = array();
function __construct($registry) {
$this->registry = $registry;
}
public function __set($index, $value)
{
$this->vars[$index] = $value;
}
function show($name) {
$path = __SITE_PATH . '/views' .'/' . $name . '.php';
if (file_exists($path) == false)
{
throw new Exception('Template not found in '. $path);
return false;
}
foreach ($this->vars as $key => $value)
{
$$key = $value;
}
include ($path);
}
}
?>

 

Recent Topics
Subject
Post Reply
Open
Recent
Program convert area
By prmindphp Wed 27 Nov 2019 11:26 am Board English Language
0
121
Wed 27 Nov 2019 11:26 am By prmindphp
Program exchange rate - Information form Bank of Thailand API
By prmindphp Tue 26 Nov 2019 2:34 pm Board English Language
0
115
Tue 26 Nov 2019 2:34 pm By prmindphp
Tracking Thailand Post Program
By prmindphp Mon 25 Nov 2019 5:47 pm Board English Language
0
147
Mon 25 Nov 2019 5:47 pm By prmindphp
Square Root Calculate Program
By prmindphp Fri 22 Nov 2019 11:30 am Board English Language
0
194
Fri 22 Nov 2019 11:30 am By prmindphp
The program calculates the mean, the variable, the standard deviation
By prmindphp Fri 22 Nov 2019 11:12 am Board English Language
0
158
Fri 22 Nov 2019 11:12 am By prmindphp
Introducing the new Mindphp.com Webboard system function (phpbb v.3.2)
By numtan5839 Tue 19 Nov 2019 6:06 pm Board English Language
0
155
Tue 19 Nov 2019 6:06 pm By numtan5839
The most popular currency pairs in the Forex for new traders
By numtan5839 Mon 18 Nov 2019 5:32 pm Board English Language
0
148
Mon 18 Nov 2019 5:32 pm By numtan5839
BIG DATA and Hadoop
By Inglejyoti Mon 18 Nov 2019 4:03 pm Board English Language
0
236
Mon 18 Nov 2019 4:03 pm By Inglejyoti
The most popular currency in the Forex
By numtan5839 Mon 18 Nov 2019 3:24 pm Board English Language
0
135
Mon 18 Nov 2019 3:24 pm By numtan5839
How to use the SQRT function in Excel
By numtan5839 Mon 18 Nov 2019 2:46 pm Board English Language
0
180
Mon 18 Nov 2019 2:46 pm By numtan5839
Deposit money into account with Thailand Post by Bank@post service
By numtan5839 Mon 18 Nov 2019 11:42 am Board English Language
0
286
Mon 18 Nov 2019 11:42 am By numtan5839
Benefits and applications of moving averages
By numtan5839 Mon 18 Nov 2019 10:47 am Board English Language
0
163
Mon 18 Nov 2019 10:47 am By numtan5839
Moving Average
By numtan5839 Sat 16 Nov 2019 2:45 pm Board English Language
0
151
Sat 16 Nov 2019 2:45 pm By numtan5839
weighted arithmetic mean
By numtan5839 Sat 16 Nov 2019 11:56 am Board English Language
0
120
Sat 16 Nov 2019 11:56 am By numtan5839
Digital Marketing Training in Mumbai
By Kanchaan Fri 15 Nov 2019 6:10 pm Board English Language
1
783
Fri 06 Dec 2019 3:16 pm By benjamin28
Thailand Post appease e-commerce with ePacket service
By numtan5839 Fri 15 Nov 2019 5:59 pm Board English Language
0
278
Fri 15 Nov 2019 5:59 pm By numtan5839
The character that precedes Tracking Number - Thailand Post Track & Trace
By numtan5839 Fri 15 Nov 2019 5:09 pm Board English Language
0
124
Fri 15 Nov 2019 5:09 pm By numtan5839
downloading MD Watermark
By bfred Fri 04 Oct 2019 3:21 pm Board English Language
6
1301
Mon 30 Dec 2019 7:26 pm By mindphp
Features Review : Component Mjform Advance untuk meningkatkan form atau borang untuk laman web dgn lebih baik
By abdkode Mon 22 Apr 2019 6:51 pm Board Bahasa Language
0
9182
Mon 22 Apr 2019 6:51 pm By abdkode
Features Review : Mhosting Components untuk mengumpul Packet hosting
By abdkode Mon 22 Apr 2019 6:50 pm Board Bahasa Language
0
1809
Mon 22 Apr 2019 6:50 pm By abdkode