Skip to content

Instantly share code, notes, and snippets.

@ta-riq
Created January 1, 2018 18:08
Show Gist options
  • Save ta-riq/81c955152cb9f65fdafd107ff69f976e to your computer and use it in GitHub Desktop.
Save ta-riq/81c955152cb9f65fdafd107ff69f976e to your computer and use it in GitHub Desktop.

Revisions

  1. ta-riq created this gist Jan 1, 2018.
    16 changes: 16 additions & 0 deletions Config.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    <?php


    return [

    'DB' => [

    'Username' => 'root',
    'Password' => '',
    'Host' => 'mysql:hostname=localhost',
    'Schema' => 'mytodo',
    'options' => []

    ]

    ];
    13 changes: 13 additions & 0 deletions about-tariq.view.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport"
    content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    </head>
    <body>
    <h1> About Tariq</h1>
    </body>
    </html>
    13 changes: 13 additions & 0 deletions about.view.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport"
    content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    </head>
    <body>
    <h1>About US</h1>
    </body>
    </html>
    13 changes: 13 additions & 0 deletions contact.view.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport"
    content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    </head>
    <body>
    <h1>Contact US</h1>
    </body>
    </html>
    19 changes: 19 additions & 0 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?php


    $query = require 'core/bootstrap.php';


    $router = new Router;

    require 'routes.php';


    $uri = trim($_SERVER['REQUEST_URI'],'/');


    require $router->direct($uri);




    153 changes: 153 additions & 0 deletions index.view.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,153 @@
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</titl<?php

    $configuration = require 'Config.php';


    require 'core/Router.php';
    require 'core/database/Connection.php';
    require 'core/database/QueryBuilder.php';

    return new QueryBuilder(Connection::make($configuration));

    <?php


    /**
    * Class Router
    */
    class Router
    {
    /**
    * @var array
    */
    protected $routes = array();

    /**
    * @param $routes
    */
    public function define($routes)
    {
    $this->routes = $routes;
    }

    /**<?php
    /**
    * Class Connection
    */
    class Connection
    {
    /**
    * @param $configuration
    * @return PDO
    */
    public static function make($configuration)
    {
    try
    {
    return new PDO
    (
    $configuration['DB']['Host'] . ';dbname='.
    $configuration['DB']['Schema'],
    $configuration['DB']['Username'],
    $configuration['DB']['Password'],
    $configuration['DB']['options']
    );
    }
    catch(PDOexception $e)
    {
    die($e->getMessage());
    }
    }
    }

    <?php

    class QueryBuilder
    {
    protected $pdo;

    public function __<?php



    require 'views/about.view.php';
    <?php





    require 'views/about-tariq.view.php';
    <?php




    require 'views/contact.view.php';

    <?php

    $tasks = $query->selectAll('todos');

    require 'views/index.view.php';
    construct($pdo)
    {
    $this->pdo = $pdo;
    }

    public function selectAll($table)
    {
    $statement = $this->pdo->prepare("SELECT * FROM {$table}");

    $statement->execute();

    return $statement->fetchAll(PDO::FETCH_CLASS);
    }
    }

    * @param $uri
    * @return mixed
    * @throws Exception
    */
    public function direct($uri)
    {
    if (array_key_exists($uri, $this->routes))
    {
    return $this->routes[$uri];
    }

    throw new Exception('No route defined for this URI.');
    }
    }e>
    </head>
    <body>

    <nav>
    <ul>
    <li><a href="about.view.php">About Page</a></li>
    <li><a href="contact.view.php">Contact Page</a></li>
    </ul>
    </nav>

    <h1>My Tasks</h1>

    <ul>
    <?php foreach($tasks as $task): ?>
    <li>
    <?php if($task->completed == true): ?>
    <strike><?= $task->description; ?></strike>
    <?php else: ?>
    <?= $task->description; ?>
    <?php endif; ?>
    </li>
    <?php endforeach; ?>
    </ul>
    </body>
    </html>
    11 changes: 11 additions & 0 deletions routes.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    <?php

    $router->define(
    [
    '' => 'controllers/index.php',
    'about' => 'controllers/about.php',
    'about/tariq' => 'controllers/about-tariq.php',
    'contact' => 'controllers/contact.php'
    ]
    );
    s