__model)) return $this->__model; // Set model to __model and return it } public function get_context_data() { return array(); } /** * Restricts access to the page based on user roles. * @return void */ protected function restrict() { switch ($this->allow_role) { case 'user': // If user is not authorized if (!CURRENT_USER) throw new HttpExceptions\Unauthorized401(); break; case 'admin': // If user is not authorized if (!CURRENT_USER) throw new HttpExceptions\Unauthorized401(); // // If user is not an admin if (!CURRENT_USER->field_is_admin) throw new HttpExceptions\PermissionDenied403(); break; default: // Nothing break; } } /** * Some function before display content */ protected function distinct() {} /** * Function if we have POST request * @return void */ protected function post() {} protected function post_before_context() {} public function __display() { $this->restrict(); // Post method if ($_SERVER['REQUEST_METHOD'] == 'POST') $this->post_before_context(); // Collect all context vars $this->context += $this->url_context + $this->get_context_data(); // Some func before display $this->distinct(); // Post method if ($_SERVER['REQUEST_METHOD'] == 'POST') $this->post(); $context = $this->context; require_once $this->template_name; } }