-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllers.html
89 lines (73 loc) · 3.73 KB
/
controllers.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
<!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>Controllers</h1>
<p>A controller is the link between a user and the system. It provides the user with input by arranging for relevant views to present themselves in appropriate places on the screen. It provides means for user output by presenting the user with menus or other means of giving commands and data. The controller receives such user output, translates it into the appropriate messages and pass these messages on to one or more of the views. <sup><a href="#source_1">[1]</a></sup></p>
<p>Controllers are loaded by the router and default to the following format:</p>
<pre class="brush: plain">
http://www.website.com/<controller>/<action>/<id>
</pre>
<p>For example, to view a user with the id 32, the following URL should work:</p>
<pre class="brush: plain">http://www.website.com/users/view/32</pre>
<p>This will call the controller Users_Controller, the action action_view and will set the id variable in the router. To get the requested id, all you have to do is:</p>
<pre class="brush: php">
$user_id = get('id')
</pre>
<p class="note">Please note that it is also possible to put controllers in a subfolder, in which case the URL format will be different. This is explained in the <a href="routing.html#custom_routes">routing documentation</a></p>
<h2>The controller class</h2>
<p>The controller class must me build from a default markup, the bare mininum for an hello world example is:</p>
<span class="bold">application/controllers/users_controller.php</span>
<pre class="brush: php">
<?php
defined('BASE_PATH') or die('No direct script access.');
class Users_Controller extends Base_Controller {
public function action_index() {
echo 'Hello world!';
}
}
?>
</pre>
<p>When you are now browsing to http://www.example.com/users you should see the text "Hello world".</p>
<p class="note">When no action is specified in the URL, it automatically defaults to action_index. If you have an action called action_new, you would need to browse to http://www.example.com/users/new.</p>
<h2>Redirect</h2>
<p>When redirecting to another page, call the following action from the controller:</p>
<pre class="brush: php">$this->redirect('users/index')</pre>
Or to redirect to an external website:
<pre class="brush: php">$this->redirect('http://www.google.com/')</pre>
<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>