HTML and CSS Reference
In-Depth Information
Adding Form Actions to the Room Controller
The Room controller supports four actions:
Joining a room
Creating a room
Opening a room
Add the following bold code to the constructor of the Room class to add support for these four actions:
Closing a room
public function __construct( $options )
$this->model = new Room_Model;
// Checks for a form submission
$this->actions = array(
'join' => 'join_room',
'create' => 'create_room',
'open' => 'open_room',
'close' => 'close_room',
if (array_key_exists($options[0], $this->actions)) {
} else {
$this->room_id = isset($options[0]) ? (int) $options[0] : 0;
if ($this->room_id===0) {
throw new Exception("Invalid room ID supplied");
$this->room = $this->model->get_room_data($this->room_id);
$this->is_presenter = $this->is_presenter();
$this->is_active = (boolean) $this->room->is_active;
The array creates a map of actions to the methods that should be called. Next, the if...else statement checks
for a valid action and, if one was passed, it calls handle_form_submission() to process it.
Joining a Room
When a user attempts to join a room, the controller needs to first check to see whether it exists using the
room_exists() method from Room_Model . If so, the user should be redirected to the requested room; if not, they
should receive an error message.
Search WWH ::

Custom Search