Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------------------------------------
- /index.php
- --------------------------------------------------------------------------------------
- <?php
- /**
- * Created by PhpStorm.
- * User: Adrian
- * Date: 2015-01-30
- * Time: 12:16
- */
- include_once ('includes/connection.php');
- include_once ('includes/article.php');
- $pagetitle = "wCMS";
- $article = new Article;
- $articles = $article->fetch_all();
- ?>
- <html>
- <head>
- <title><?php echo $pagetitle ?></title>
- <link rel="stylesheet" href="includes/templates/default/style.css" />
- </head>
- <body>
- <div class="container">
- <a href="index.php" id="Logo"><?php echo $pagetitle ?></a>
- <ol>
- <?php foreach ($articles as $article) { ?>
- <li>
- <a href="article.php?id=<?php echo $article['article_id']; ?>">
- <?php echo $article['article_title']; ?>
- </a>
- - <small>
- dodano <?php echo date('l jS', $article['article_timestamp']); ?>
- </small>
- </li>
- <?php } ?>
- </ol>
- </div>
- </body>
- </html>
- --------------------------------------------------------------------------------------
- /article.php
- --------------------------------------------------------------------------------------
- <?php
- /**
- * Created by PhpStorm.
- * User: Adrian
- * Date: 2015-01-30
- * Time: 15:33
- */
- $pagetitle = "wCMS";
- include_once ('includes/connection.php');
- include_once ('includes/article.php');
- $article = new Article();
- if (isset($_GET['id'])) {
- $id = $_GET['id'];
- $data = $article->fetch_data($id);
- ?>
- <html>
- <head>
- <title><?php echo $pagetitle ?></title>
- <link rel="stylesheet" href="includes/templates/default/style.css" />
- </head>
- <body>
- <div class="container">
- <a href="index.php" id="Logo"><?php echo $pagetitle ?></a>
- <h4><?php echo $data['article_title'] ?> -
- <small>
- <?php echo date('l jS', $data['article_timestamp']) ?>
- </small>
- </h4>
- <p><?php echo $data['article_content']; ?></p>
- <a href="index.php">← Wstecz</a>
- </div>
- </body>
- </html>
- <?php
- } else {
- header('Location: index.php');
- exit();
- }
- --------------------------------------------------------------------------------------
- /includes/article.php
- --------------------------------------------------------------------------------------
- <?php
- /**
- * Created by PhpStorm.
- * User: Adrian
- * Date: 2015-01-30
- * Time: 15:02
- */
- class Article {
- public function fetch_all() {
- global $pdo;
- $query = $pdo->prepare("SELECT * FROM articles");
- $query->execute();
- return $query->fetchAll();
- }
- public function fetch_data($article_id) {
- global $pdo;
- $query = $pdo->prepare("SELECT * FROM articles WHERE article_id = ?");
- $query->bindValue(1, $article_id);
- $query->execute();
- return $query->fetch();
- }
- }
- ?>
- --------------------------------------------------------------------------------------
- /includes/connection.php
- --------------------------------------------------------------------------------------
- <?php
- /**
- * Created by PhpStorm.
- * User: Adrian
- * Date: 2015-01-30
- * Time: 14:38
- */
- try {
- $pdo = new PDO('mysql:host=localhost;dbname=wcms', 'root', 'moje_haslo');
- } catch (PDOException $e) {
- exit('Brak połączenia z bazą');
- }
- --------------------------------------------------------------------------------------
- includes/templates/default/style.css
- --------------------------------------------------------------------------------------
- body {
- padding-top: 120px;
- font-family: Arial;
- }
- .containter {
- width: 500px;
- margin: 0 auto;
- }
- a:link, a:visited {
- color: slategray;
- text-decoration: none;
- border-bottom: 1px dotted slategray;
- }
- a:hover {
- color: #444;
- border-bottom-color: #444;
- }
- small {
- color: #999;
- font-style: italic;
- }
- p {
- line-height: 30px;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement