protected function actionSave() { try { if (isset($_POST['id'])) { $news = \App\Models\News::findById($_POST['id']); if (!$news) { throw new \App\Exceptions\Err404('Новость не найдена '); } } else { $news = new \App\Models\News(); } $news->fill($_POST); $news->save(); header('Location: /admin/index'); exit; } catch (\Lib\MultiException $e) { $this->view->errors = $e; $logger = new \App\LogUseLib(); $logger->getArrMess($e); $this->view->news = $news; $this->view->display(__DIR__ . '/../templates/admin/edit.php'); } }
$control = array_shift($uri_parts); // alias контроллера if (count($uri_parts) >= 1) { $action = array_shift($uri_parts); // alias action } } $ctrl = '\\App\\Controllers\\' . $control; if (!class_exists($ctrl)) { $e = new \App\Exceptions\Err404('Неверный адрес '); $e->setExtParams(['uri' => $_SERVER['REQUEST_URI'], 'ctrl' => $ctrl]); throw $e; } $controller = new $ctrl(); if (!method_exists($controller, 'action' . $action)) { $e = new \App\Exceptions\Err404('Несуществующий адрес '); $e->setExtParams(['uri' => $_SERVER['REQUEST_URI'], 'ctrl' => $ctrl, 'act' => $action]); throw $e; } $controller->action($action); } catch (\App\Exceptions\DB $e) { $err = new \App\Controllers\Error(); $err->actionDbError($e->getMessage()); $logger = new \App\LogUseLib(); $logger->emergency($e->getMessage(), $e->getMess()); } catch (\App\Exceptions\Err404 $e) { $err = new \App\Controllers\Error(); $err->action404($e->getMessage()); $logger = new \App\LogUseLib(); $logger->alert($e->getMessage(), $e->getMess()); }