public function _before(\framework\core\Request &$request, \framework\core\Response &$response) { $var = $request->getParams(); if (empty($var)) { $url = $this->getConfig("siteUrl") . "user"; $this->getComponent("httpResponse")->redirect($url); } }
public function dispatch(\framework\core\Request $request) { $config = $this->getConfig('modulesLocation'); $actionExists = false; if (isset($config[$request->getModule()])) { $classname = $this->getModuleNamespace($request->getModule()) . '\\controllers\\' . $request->getAction(); if (\class_exists($classname)) { $actionExists = true; } } if (!$actionExists) { return $this->createRequest('errors', 'error404', array(), $request->getState())->execute(); } $module = $this->getComponent('action', $classname); $response = $this->getComponent('response'); return $module->execute($request, $response); }
/** * @param Request $request * @param Response $response * @return string */ public function index($request, $response) { $exception = $request->getParams()["exception"]; $response->setParams(array("errorMessage" => $exception)); return "error"; }
/** * @param Request $request * @param Response $response */ public function delete($request, $response) { try { Student::setRegistry($this->registry); $params = $request->getParams(); $student = Student::find($params["id"]); $student->delete(); } catch (ModelException $e) { $response->setParams(array("exception" => $e->getMessage())); $response->sendRedirect("error"); } $response->sendRedirect("students"); }
use framework\core\ConfigManager; define('ROOT', $_SERVER['DOCUMENT_ROOT']); require_once ROOT . "/framework/core/loader.php"; spl_autoload_register(array("framework\\core\\Loader", "loadClass")); $registry = new Registry(); $db = new PDO(ConfigManager::getConfig("db")); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $registry["db"] = $db; $logger = new Logger(ROOT . ConfigManager::getConfig("log_file")); $registry["logger"] = $logger; $router = Router::getInstance($registry); if (isWebFileRequested() > 0) { readfile(ROOT . $_SERVER['REQUEST_URI']); } else { $urlParts = explode('?', $_SERVER['REQUEST_URI'], 2); $request = new Request($urlParts[0]); $request->setParams($_REQUEST); $response = new Response(); $controllerData = $router->getController($request->getUrl()); $controller = $controllerData["controller"]; if ($controller != "index") { $action = $controllerData["action"]; $view = $controller->{$action}($request, $response); if ($response->getPath() == "") { $response->setPath(ROOT . "/src/Students/view"); } $template = new Template($view, $response); $template->show(); } else { $response->sendRedirect("students"); }
protected function _before(\framework\core\Request &$request, \framework\core\Response &$response) { if ($request->getState() != \framework\core\Request::CLI_STATE) { //$this->getContainer()->getNewRequest('errors', 'error403', array($request))->execute(); } }