Esempio n. 1
0
 public function edit()
 {
     $news_collection = new NewsCollection();
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $news = new NewsEntity();
         $news->setId($_GET['id'])->setTitle($_POST['title'])->setContent($_POST['content'])->setAuthor($_POST['author'])->setDate($_POST['date_added']);
         if ($_FILES['image']['tmp_name'] != '') {
             $news->saveImage($_FILES['image']);
         }
         $news_collection->save($news);
         header('Location: index.php?controller=news');
     }
     $data = $news_collection->get($_GET['id']);
     $this->loadView('cms/news_edit', array('data' => $data));
 }
Esempio n. 2
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();
?>