Esempio n. 1
0
<?php

require_once __DIR__ . '/../common/autoload_cms.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $entity = new News();
    $entity->setId($_GET['id'])->setTitle($_POST['title'])->setContent($_POST['content'])->setAuthor($_POST['author'])->setDateAdded(date('Y-m-d H:i:s'));
    $newsCollection = new NewsCollection();
    $newsCollection->save($entity);
    header('Location: news_list.php');
    exit;
}
$newsCollection = new NewsCollection();
$article = $newsCollection->one(array('id' => $_GET['id']));
require_once 'include/header.php';
?>

    <div class="container">
        <form method="post" action="" enctype="multipart/form-data">
            <div class="form-group">
                <label for="title">Title:</label>
                <input type="text" name="title" id="title" value="<?php 
echo $article->getTitle();
?>
" class="form-control">
            </div>

            <div class="form-group">
                <label for="content">Content:</label>
                <textarea name="content" id="content" class="form-control" rows="10"><?php 
echo $article->getContent();
?>
Esempio n. 2
0
 protected function processForm(HTTPRequest $request)
 {
     if ($request->method() == 'POST') {
         $news = new News(['auteur' => $request->postData('auteur'), 'titre' => $request->postData('titre'), 'contenu' => $request->postData('contenu')]);
         if ($request->getExists('id')) {
             $news->setId($request->getData('id'));
         }
     } else {
         // L'identifiant de la news est transmis si on veut la modifier
         if ($request->getExists('id')) {
             $news = $this->getManagerOf($this->module(), 'News')->getUnique($request->getData('id'));
         } else {
             $news = new News();
         }
     }
     $formBuilder = new NewsFormBuilder($news);
     $formBuilder->build();
     $form = $formBuilder->form();
     $formHandler = new FormHandler($form, $this->getManagerOf($this->module(), 'News'), $request);
     if ($formHandler->process()) {
         $this->app->session()->setFlash($news->isNew() ? 'La news a bien été ajoutée !' : 'La news a bien été modifiée !');
         $this->app->httpResponse()->redirect('/admin/');
     }
     $this->page->addVar('form', $form->createView());
 }
Esempio n. 3
0
<?php

require 'classes/autoload.php';
$db = DBFactory::getMysqlConnexionWithPDO();
$manager = new NewsManagerPDO($db);
if (isset($_GET['modifier'])) {
    $news = $manager->getUnique((int) $_GET['modifier']);
}
if (isset($_GET['supprimer'])) {
    $manager->delete((int) $_GET['supprimer']);
    $message = 'La news a bien été supprimée !';
}
if (isset($_POST['auteur'])) {
    $news = new News(['auteur' => $_POST['auteur'], 'titre' => $_POST['titre'], 'contenu' => $_POST['contenu']]);
    if (isset($_POST['id'])) {
        $news->setId($_POST['id']);
    }
    if ($news->isValid()) {
        $manager->save($news);
        $message = $news->isNew() ? 'La news a bien été ajoutée !' : 'La news a bien été modifiée !';
    } else {
        $erreurs = $news->getErreurs();
    }
}
?>
<!DOCTYPE html>
 <html lang="fr">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">