Controllers use tasks, string names, to identify what we want to do. Within the
controller, there is a task map, which is used to map task names to methods. When
we instantiate a new controller, the task map is automatically populated with task
and method names.
If we had a JController subclass with three methods, foo(), bar(), and _baz(), our
task map would look like this:
Task Method
foo foo()
bar bar()
Notice that the _baz() method is missing; this is because _baz() is a private
method, which is denoted by the underscore at the start of the name. The task map
uses a many-to-one relationship: we can define many tasks for one method. To add
additional entries to the task map we can use the registerTask() method. More
information about this method is available in the Appendix.
Within JController there is a special method called execute(). This method is used
to execute a task. For example, if we wanted to execute the task foo, we would use
the following:
$controller->execute('foo');
Chapter 4
[ 79 ]
Assuming $controller is using the task map we spoke of earlier, the controller will
execute the foo() method.
Pages:
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118