HTML and CSS Reference
In-Depth Information
This method starts by validating the nonce; it then calls the action handler method and stores the output in a
variable. For this app, every action will return a room ID, so the method checks to make sure one was returned. Using
the room ID, the user is then redirected to the room in which she should be viewing.
Adding an Action Method to the Controller
To actually process the submitted form data, a new method needs to be added to the Controller class that outputs
the form. Using our previous Example class, the two actions defined would require that methods called say_foo() and
say_bar() were added to the Example class, which is shown here in bold:
class Example extends Controller
public function __construct( $options )
$this->actions = array(
'action-one' => 'say_foo',
if (array_key_exists($options[0], $this->actions)) {
} else {
// If we get here, no form was submitted...
/* get_title() and output_view() would go here */
protected function say_foo( )
$room_id = $this->sanitize($_POST['room_id']);
$sayer_id = $this->sanitize($_POST['sayer_id']);
echo 'Foo!';
return $this->model->update_foo_count($room_id, $sayer_id);
First, this method grabs any data that was passed from the submitted form, sanitizes it, and stores it in a variable.
Even though this method is just an example, the $room_id is being passed to follow suit with the action handlers that
will exist in the app.
Next, the action handler performs the requested action: in this case, outputting the string, “Foo!” to the screen.
Finally, it executes the model method and returns the result.
Search WWH ::

Custom Search