コード例 #1
0
ファイル: BlogController.php プロジェクト: php-user/shop.loc
 public function actionView($id)
 {
     $categories = CategoryModel::getAllUsingColumns();
     $blog = BlogModel::getById($id);
     $view = new View();
     $view->categories = $categories;
     $view->blog = $blog;
     $view->display('blog/view.php');
     return true;
 }
コード例 #2
0
 public function actionEdit($id)
 {
     $errors = [];
     $blog = BlogModel::getById($id);
     if (isset($_POST['submit'])) {
         $title = FL::clearStr($_POST['title']);
         $description = FL::clearStr($_POST['description']);
         $content = FL::clearStr($_POST['content']);
         if (!FL::isValue($title)) {
             $errors[] = 'Название не может быть пустым';
         }
         if (!FL::isValue($description)) {
             $errors[] = 'Описание не может быть пустым';
         }
         if (!FL::isValue($content)) {
             $errors[] = 'Контент не может быть пустым';
         }
         if (empty($errors)) {
             $blog->title = $title;
             $blog->description = $description;
             $blog->content = $content;
             $res = $blog->save();
             if ($res) {
                 if ($_FILES['image']['name'] && $_FILES['image']['type'] == 'image/jpeg') {
                     $fileName = 'blog' . $id . '.jpg';
                     $tmpName = $_FILES['image']['tmp_name'];
                     if (is_uploaded_file($tmpName)) {
                         $imagePath = '/images/blog/' . $fileName;
                         $destination = ROOT . '/template/images/blog/' . $fileName;
                         $result = move_uploaded_file($tmpName, $destination);
                         if ($result) {
                             $blog->image = $imagePath;
                             $blog->save();
                         }
                     }
                 }
             }
             FL::redirectTo('/admin/blog');
         }
     }
     $view = new View();
     $view->blog = $blog;
     $view->errors = $errors;
     $view->display('admin_blog/edit.php');
     return true;
 }