public function actionIndex() { $this->view->news = Article::findAllWithGenerator(); $this->view->table = (new AdminDataTable(Author::findAll(), [function ($model) { return $model->getName(); }, function ($model) { return $model->getEmail(); }]))->render(); $this->view->display(__DIR__ . '/../../templates/admin.php'); }
/** * Экшен для сохранения новости */ protected function actionSave() { $article = \App\Models\Article::giveOne($_POST['id']); if (false === $article) { throw new \App\Exceptions\ObjectNotFound('Запрашиваемый объект не найден'); } $article->fill($_POST); $article->author = \App\Models\Author::giveOne($_POST['author_id']); try { $article->save(); $this->redirect('/admin'); } catch (\App\MultiException $ex) { $this->view->article = $article; $this->view->authors = \App\Models\Author::findAll(); $this->view->errors = $ex; $this->view->display(__DIR__ . '/../../templates/admin/news/tmp_edit.php'); } }
protected function actionEdit() { $id = $_GET['id'] ?? false; if (false !== $id) { if (false === ($article = \App\Models\News::findByID($id))) { throw new \App\Exceptions\NotFound($_SERVER['REQUEST_URI']); } } else { $article = new \App\Models\News(); } if (!empty($_POST)) { try { $article->fillByPost($_POST); } catch (MultiException $e) { $this->view->display('edit.php', ['article' => $article, 'authors' => \App\Models\Author::findAll(), 'errors' => $e]); exit(0); } $this->redirectIf('/admin/news/index', $article->save()); } $this->view->display('edit.php', ['article' => $article, 'authors' => \App\Models\Author::findAll()]); }
protected function actionAuthors() { $authors = Author::findAll(); $table = new AdminDataTable($authors, [function (Author $author) { return $author->firstname; }, function (Author $author) { return $author->lastname; }, function (Author $author) { return $author->email; }]); $this->view->render('/admin/authors.html', ['authors' => $table->render()]); }
<?php /** * Подключение файла автозагрузки */ require_once __DIR__ . '/../../autoload.php'; $view = new \App\View(); $view->title = 'Админ-панель'; $view->content = 'Контент'; $view->authors = \App\Models\Author::findAll(); /* foreach($view->authors as $key => $value) { echo gettype($value) . '<br>'; if (!is_object($value) && !is_array($value)) { continue; } echo ++$key . '). '; $iter = new App\MyIterator($value); foreach ($iter as $k => $v) { if (!is_object($v) && !is_array($v)) { echo $k . ' = ' . $v . '; '; continue; } $iter2 = new App\MyIterator($v); foreach ($iter2 as $k2 => $v2) { echo $k2 . ' = ' . $v2 . '; '; }