$controller = new Controller_Search(); // Использовал @, потому что не нашел другого решения return $controller->getSearchResults($_POST['name'], @$_POST['price'], @$_POST['producer'], @$_POST['category']); }); // Ошибки $router->onHttpError(function ($code) { switch ($code) { case 404: $controller = new Controller_404(); $controller->action_index(); break; } }); // Страница 404 $router->respond('404/?', function () { $controller = new Controller_404(); $controller->action_index(); }); // Страница авторизации $router->respond('GET', '/login/?', function ($request) { $controller = new Controler_authorization(); return $controller->getLogin(); }); // Авторизация $router->respond('POST', '/login/?', function ($request) { $controller = new Controler_authorization(); return json_encode($controller->setLogin($request->login, $request->password)); }); // Выход $router->respond('POST', '/logout/?', function ($request) { $controller = new Controler_authorization();
/** * 404 */ public function error404() { /* * for some reasons, clear previous controller and model */ $this->request[1] = '404'; $this->controller = NULL; $this->model = NULL; $this->action['name'] = 'action_index'; http_response_code(404); if (!class_exists('Controller_404')) { require_once ROOT . "application/controllers/controller_404.php"; } /* same for model */ if (!class_exists('Model_404')) { require_once ROOT . "application/models/model_404.php"; } /* needed 404 name */ $this->model = new Model_404(); $controller = new Controller_404($this); $controller->action_index(); exit(0); }
public function getProduct($id) { $product = $this->model->get($id); if ($product) { $categoryTitle = $this->model->getCatalogName($product->id_category); $count = $product->count > 6 ? 6 : $product->count; $product->producer = $this->model->getProducer($product->id_producer)->title; return $this->view->render('products/item_view.twig', array('title' => $product->title, 'product' => $product, 'count' => $count, 'category' => $categoryTitle)); } else { $error404 = new Controller_404(); return $error404->action_index(); } }