Ejemplo n.º 1
0
 public function createAction()
 {
     $this->assets->addCss('css/select2.css');
     $this->assets->addJs('js/select2.min.js');
     if ($this->request->isPost() && !$this->request->isAjax()) {
         $auth = $this->session->get('auth');
         if (!$auth) {
             return $this->response->redirect();
         }
         $model = new \Models\Posts();
         $model->author_id = $auth['id'];
         if (!$model->create($_POST)) {
             foreach ($model->getMessages() as $message) {
                 $this->flashSession->error((string) $message->getMessage());
             }
             return $this->response->redirect('backend/posts/create');
         } else {
             $this->flashSession->success("Запись удачно создана");
             return $this->response->redirect("backend/posts");
         }
     }
     $this->view->setVar('tags', \Models\Tags::getTagsForSelect());
 }
<?php

if (!defined('SH_API_DIR')) {
    exit;
}
$app->get('/posts', function () use($app) {
    $postsObj = new Models\Posts();
    $posts = $postsObj->getAll();
    json_response($posts);
});