Пример #1
0
<?php

require_once __DIR__ . '/classes/manager/SimplePostManager.class.php';
session_start();
if (!isset($_SESSION['user'])) {
    header('Location: ./login.php');
}
$pm = new SimplePostManager();
// si le champs submit est présent, alors le formulaire a été envoyé
if (isset($_POST['submit'])) {
    $title = isset($_POST['title']) ? $_POST['title'] : '';
    $body = isset($_POST['body']) ? $_POST['body'] : '';
    $pm->addPost($title, $body, $_SESSION['user']);
    header('Location: ./postList.php');
}
?>

<!DOCTYPE html>
<html>
    <head>
        <title>Add Post</title>
    </head>
    <body>
        <h1>Add Post Page</h1>
        <form action="#" method="post">
            <label for="title">Title:</label>
            <input type="text" id="title" name="title" value="" />
            <br />
            <label for="body">Body:</label>
            <textarea id="body" name="body"></textarea>
            <br />
Пример #2
0
<?php

require_once __DIR__ . '/classes/manager/SimplePostManager.class.php';
require_once __DIR__ . '/classes/entities/User.class.php';
session_start();
if (!isset($_SESSION['user'])) {
    header('Location: ./login.php');
}
$pm = new SimplePostManager();
?>

<!DOCTYPE html>
<html>
    <head>
        <title>Posts list</title>
    </head>
    <body>
        <h1>Posts List Page</h1>
        <ul>
            <?php 
foreach ($pm->findAllPosts() as $post) {
    ?>
                <li>
                    <ul>
                        <li><?php 
    echo $post->getTitle();
    ?>
</li>
                        <li><?php 
    echo $post->getBody();
    ?>