-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.html
117 lines (100 loc) · 4.1 KB
/
views.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<title>Menukaarten-docs</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="assets/css/stylesheet.css" media="screen,print">
<link rel="stylesheet" href="assets/css/print.css" media="print">
<link rel="stylesheet" type="text/css" href="assets/css/shCore.css" media="screen,print">
<link rel="stylesheet" type="text/css" href="assets/css/shThemeDefault.css" media="screen,print">
<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/SyntaxHighlighter.js"></script>
<script type="text/javascript" src="assets/js/build_menu.js"></script>
</head>
<body>
<div id="header-wrapper">
<div id="header">
<h1>Documentation SexyFramework</h1>
<span>Created by Vincent Bremer & Douwe de Haan</span>
</div>
</div>
<div id="container">
<div id="menu-wrapper">
<div id="menu">
<h1>Table of contents</h1>
<ul></ul>
</div>
</div>
<div id="content-wrapper">
<div id="content">
<!-- START CONTENT -->
<h1>Views</h1>
<p>
A view is a (visual) representation of its model. It would ordinarily highlight certain attributes of the model and suppress others. It is thus acting as a presentation filter.
</p>
<p>
A view is attached to its model (or model part) and gets the data necessary for the presentation from the model by asking questions. It may also update the model by sending appropriate messages. All these questions and messages have to be in the terminology of the model, the view will therefore have to know the semantics of the attributes of the model it represents. <sup><a href="#source_1">[1]</a></sup>
</p>
<h2>Rendering views</h2>
<p>All views are loaded from the directory application/views
In case you want to render the file index.php from the directory application/views/users/ all you need to do in the controller is the following:</p>
<pre class="brush: php">
$this->view->render('users/index')
</pre>
<h2>Setting a template</h2>
<p>By default the template file templates/default.php is loaded in the view. The content of the view is then passed to a $content variable. To create a new template you can do the following:
<ol class="list">
<li>Create the file <span class="bold">test.php</span> in the directory <span class="bold">templates</span></li>
<li>Copy and paste the following code in that file, and save it.</li>
</ol>
<pre class="brush: html">
<!DOCTYPE html>
<html>
<head>
<title>Template test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="content">
<?php echo $content ?>
</div>
</body>
</html>
</pre>
<p>Then, in the controller, you can load the new template and render a view in it with:</p>
<pre class="brush: php">
$view = load::view('test');
$view->render('users/index');
</pre>
<h2>Flash messages:</h2>
<p>
To display a message after a page redirect you can use the following flash message. The flash message acc
</p>
For an error message the msg function accepts 3 variables; class, title and an optional array with errors, for example:<br>
<pre class="brush: php">
$errors = array('Username cant be blank', 'No valid e-mail address entered');
$this->view->msg('error', 'User not saved, the following errors occurd', $errors);
</pre>
To display a notification:<br>
<pre class="brush: php">
$this->view->msg('notification', 'Please update you settings');
</pre>
To display a success message:<br>
<pre class="brush: php">
$this->view->msg('success', 'User has been successfully saved.');
</pre>
<!--
$this->view->set('user', $_POST);
$this->view->render('users/login');
$this->render_msg()
-->
<p class="footnote">
[1] - <a href="http://www.codinghorror.com/blog/2008/05/understanding-model-view-controller.html" id="source_1" target="_blank">Codinghorror - Understanding model-view-controller</a> - 5 May 2008<br>
</p>
<!-- END CONTENT -->
</div>
</div>
</div>
<script type="text/javascript" src="assets/js/SyntaxHighlighter_settings.js"></script>
</body>
</html>