コード例 #1
0
ファイル: article.php プロジェクト: ChupinDO/blog_mongodb
<?php

/**
 * Created by PhpStorm.
 * User: Даниил
 * Date: 03.10.2015
 * Time: 16:05
 */
require_once "DBClient.php";
require_once "models/ArticlesCollection.php";
require_once "models/CommentsCollection.php";
$link = DBClient::connect();
$articles_collection = new ArticlesCollection($link);
$article = $articles_collection->get_one($_GET["id"]);
$comments_collection = new CommentsCollection($link);
$comments = $comments_collection->get_all_for_article($_GET["id"]);
$comments = array_reverse($comments, true);
$count = count($comments);
if (!empty($_GET["action"])) {
    $action = $_GET["action"];
    switch ($action) {
        case "delete":
            $comments_collection->delete($_GET["comment_id"]);
            header("Location: article.php?id=" . $_GET["id"]);
            DBClient::close($link);
            die;
            break;
    }
}
if (empty($_POST)) {
    include "views/article.php";
コード例 #2
0
ファイル: index.php プロジェクト: ChupinDO/blog_mongodb
            $article = ["date" => $_POST["date"], "title" => $_POST["title"], "content" => $_POST["content"]];
            $articles_collection->add($article);
            header("Location: index.php");
        }
        $article = ["date" => "", "title" => "", "content" => ""];
        include "../views/article_admin.php";
        break;
    case "delete":
        //получаем параметр id
        $id = $_GET["id"];
        //удаляем статью из базы
        $articles_collection->delete($id);
        //перенаправляем браузер на index.php
        header("Location: index.php");
        break;
    case "edit":
        $id = $_GET["id"];
        if (!empty($_POST)) {
            $new_article = ["date" => $_POST["date"], "title" => $_POST["title"], "content" => $_POST["content"]];
            $articles_collection->edit($id, $new_article);
            header("Location: index.php");
        }
        $article = $articles_collection->get_one($id);
        include "../views/article_admin.php";
        break;
    default:
        $articles = $articles_collection->get_all();
        include "../views/articles_admin.php";
}
//в завершении любой операции закрывам соединение
DBClient::close($link);