/** * Use this function to set default parameters for specific actions * * It's also a good way to transform request variables to proper parameters */ public static function checkParameters($parameters) { //If there's no action, only a ID, use the request verb to determine the action if (is_numeric(Controller::$action)) { $parameters[0] = Controller::$action; switch (strtoupper($_SERVER['REQUEST_METHOD'])) { case 'DELETE': Controller::setAction('delete'); break; case 'PUT': Controller::setAction('create'); break; case 'POST': Controller::setAction('update'); break; case 'GET': default: Controller::setAction('display'); break; } } //List instead of index if (Controller::$action == 'index') { Controller::setAction('list'); } switch (Controller::$action) { case 'list': //Defaults for List if (!isset(Controller::$parameters[0])) { $parameters[0] = 0; } if (!isset(Controller::$parameters[1])) { $parameters[1] = ConfigValue::get('table.ListLength', 5); } break; case 'search': //Defaults for Search //Get the search term from the request variable. It's always the first parameter if ($term = Controller::getVar('term')) { array_unshift($parameters, $term); } else { if (!count($parameters)) { $parameters[0] = ''; } } if (!isset(Controller::$parameters[1])) { $start = Controller::getVar('start', FILTER_VALIDATE_INT); $parameters[1] = is_null($start) ? 0 : $start; } if (!isset(Controller::$parameters[2])) { $count = Controller::getVar('count', FILTER_VALIDATE_INT); $parameters[2] = is_null($count) ? ConfigValue::get('table.ListLength', 5) : $count; } break; } //Get the delete_id from the request variable if (Controller::$action == 'delete' && empty($parameters[0]) && ($delete_id = Controller::getVar('delete_id', FILTER_VALIDATE_INT))) { $parameters[0] = $delete_id; } return $parameters; }
public static function checkParameters($parameters) { if (Controller::$action == 'index') { Controller::setAction('list'); } if (Controller::$action == 'list' && !isset(Controller::$parameters[0])) { $parameters[0] = 0; } if (Controller::$action == 'list' && !isset(Controller::$parameters[1])) { $parameters[1] = ConfigValue::get('table.ListLength', 9); } return parent::checkParameters($parameters); }
public static function checkParameters($parameters) { $parameters = parent::checkParameters($parameters); if (!method_exists(get_called_class(), 'action_' . Controller::$action) && !method_exists(get_called_class(), 'get_' . Controller::$action) && !method_exists(get_called_class(), 'post_' . Controller::$action) && !method_exists(get_called_class(), 'put_' . Controller::$action) && !method_exists(get_called_class(), 'delete_' . Controller::$action)) { $parameters[0] = Controller::$action; Controller::setAction('display'); } return $parameters; }
public static function checkParameters($parameters) { $parameters = parent::checkParameters($parameters); switch (Controller::$action) { case 'login': if (empty($parameters[0])) { $parameters[0] = Controller::getVar('username'); } if (empty($parameters[1])) { $parameters[1] = Controller::getVar('password'); } break; case 'confirm': if (empty($parameters[0])) { $parameters[0] = Controller::getVar('salt'); } case 'signup': if (array_key_exists('user', $_SESSION) && $_SESSION['BackendUser']->id > 0) { Controller::setAction('display'); } break; case 'update': case 'display': if (array_key_exists('BackendUser', $_SESSION) && $_SESSION['BackendUser']->id > 0) { //If empty, set it to the current user if (empty($parameters['0'])) { $parameters[0] = $_SESSION['BackendUser']->id; } //If not set to current user, and user doesn't have permissions, set to current user if ($parameters[0] != $_SESSION['BackendUser']->id && !Permission::check('manage', class_for_url(get_called_class())) && Permission::check(Controller::$action, class_for_url(get_called_class()))) { $parameters[0] = $_SESSION['BackendUser']->id; } } break; } return $parameters; }
/** * Internally redirects one action to another. Does not perform another HTTP request unlike Controller::redirect() * * @param string $action The new action to be 'redirected' to * @return mixed Returns the return value of the called action */ public function setAction($action) { $this->request->params['action'] = $action; return parent::setAction($action); }
<?php // DO NOT FORGET: "LESS IS MORE" session_start(); require_once "./api.php"; $main = new Main(); $ctr = new Controller(); $ctr->setAction(request::get("action")); $ctr->setModule(request::get("controller")); $ctr->setFormat(request::get("format")); CoreController::share($ctr, $main); $main->assign('content', $ctr); $main->render();