├── app ├── controllers │ ├── PagesController.php │ └── UsersController.php ├── routes.php └── views │ ├── about-culture.view.php │ ├── about.view.php │ ├── contact.view.php │ ├── index.view.php │ ├── partials │ ├── footer.php │ ├── head.php │ └── nav.php │ └── users.view.php ├── composer.json ├── config.php ├── core ├── App.php ├── Request.php ├── Router.php ├── bootstrap.php ├── database │ ├── Connection.php │ └── QueryBuilder.php └── helpers.php ├── index.php └── public └── css └── style.css /app/controllers/PagesController.php: -------------------------------------------------------------------------------- 1 | $company]); 23 | } 24 | 25 | /** 26 | * Show the contact page. 27 | */ 28 | public function contact() 29 | { 30 | return view('contact'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/controllers/UsersController.php: -------------------------------------------------------------------------------- 1 | selectAll('users'); 15 | 16 | return view('users', compact('users')); 17 | } 18 | 19 | /** 20 | * Store a new user in the database. 21 | */ 22 | public function store() 23 | { 24 | App::get('database')->insert('users', [ 25 | 'name' => $_POST['name'] 26 | ]); 27 | 28 | return redirect('users'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/routes.php: -------------------------------------------------------------------------------- 1 | get('', 'PagesController@home'); 4 | $router->get('about', 'PagesController@about'); 5 | $router->get('contact', 'PagesController@contact'); 6 | 7 | $router->get('users', 'UsersController@index'); 8 | $router->post('users', 'UsersController@store'); -------------------------------------------------------------------------------- /app/views/about-culture.view.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Our Culture at

4 | 5 | 6 | -------------------------------------------------------------------------------- /app/views/about.view.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |

About

4 | 5 | 6 | -------------------------------------------------------------------------------- /app/views/contact.view.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Contact Us

4 | 5 | 6 | -------------------------------------------------------------------------------- /app/views/index.view.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Home Page

4 | 5 | 6 | -------------------------------------------------------------------------------- /app/views/partials/footer.php: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/views/partials/head.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/views/partials/nav.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/views/users.view.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |

All Users

4 | 5 | 6 |
  • name; ?>
  • 7 | 8 | 9 |

    Submit Your Name

    10 | 11 |
    12 | 13 | 14 |
    15 | 16 | 17 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "autoload": { 3 | "classmap": [ 4 | "./" 5 | ], 6 | "files": ["core/helpers.php"] 7 | } 8 | } -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'name' => 'mytodo', 6 | 'username' => 'root', 7 | 'password' => '', 8 | 'connection' => 'mysql:host=127.0.0.1', 9 | 'options' => [ 10 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION 11 | ] 12 | ] 13 | ]; 14 | -------------------------------------------------------------------------------- /core/App.php: -------------------------------------------------------------------------------- 1 | [], 14 | 'POST' => [] 15 | ]; 16 | 17 | /** 18 | * Load a user's routes file. 19 | * 20 | * @param string $file 21 | */ 22 | public static function load($file) 23 | { 24 | $router = new static; 25 | 26 | require $file; 27 | 28 | return $router; 29 | } 30 | 31 | /** 32 | * Register a GET route. 33 | * 34 | * @param string $uri 35 | * @param string $controller 36 | */ 37 | public function get($uri, $controller) 38 | { 39 | $this->routes['GET'][$uri] = $controller; 40 | } 41 | 42 | /** 43 | * Register a POST route. 44 | * 45 | * @param string $uri 46 | * @param string $controller 47 | */ 48 | public function post($uri, $controller) 49 | { 50 | $this->routes['POST'][$uri] = $controller; 51 | } 52 | 53 | /** 54 | * Load the requested URI's associated controller method. 55 | * 56 | * @param string $uri 57 | * @param string $requestType 58 | */ 59 | public function direct($uri, $requestType) 60 | { 61 | if (array_key_exists($uri, $this->routes[$requestType])) { 62 | return $this->callAction( 63 | ...explode('@', $this->routes[$requestType][$uri]) 64 | ); 65 | } 66 | 67 | throw new Exception('No route defined for this URI.'); 68 | } 69 | 70 | /** 71 | * Load and call the relevant controller action. 72 | * 73 | * @param string $controller 74 | * @param string $action 75 | */ 76 | protected function callAction($controller, $action) 77 | { 78 | $controller = "App\\Controllers\\{$controller}"; 79 | $controller = new $controller; 80 | 81 | if (! method_exists($controller, $action)) { 82 | throw new Exception( 83 | "{$controller} does not respond to the {$action} action." 84 | ); 85 | } 86 | 87 | return $controller->$action(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /core/bootstrap.php: -------------------------------------------------------------------------------- 1 | getMessage()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/database/QueryBuilder.php: -------------------------------------------------------------------------------- 1 | pdo = $pdo; 24 | } 25 | 26 | /** 27 | * Select all records from a database table. 28 | * 29 | * @param string $table 30 | */ 31 | public function selectAll($table) 32 | { 33 | $statement = $this->pdo->prepare("select * from {$table}"); 34 | 35 | $statement->execute(); 36 | 37 | return $statement->fetchAll(PDO::FETCH_CLASS); 38 | } 39 | 40 | /** 41 | * Insert a record into a table. 42 | * 43 | * @param string $table 44 | * @param array $parameters 45 | */ 46 | public function insert($table, $parameters) 47 | { 48 | $sql = sprintf( 49 | 'insert into %s (%s) values (%s)', 50 | $table, 51 | implode(', ', array_keys($parameters)), 52 | ':' . implode(', :', array_keys($parameters)) 53 | ); 54 | 55 | try { 56 | $statement = $this->pdo->prepare($sql); 57 | 58 | $statement->execute($parameters); 59 | } catch (\Exception $e) { 60 | // 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /core/helpers.php: -------------------------------------------------------------------------------- 1 | direct(Request::uri(), Request::method()); 10 | -------------------------------------------------------------------------------- /public/css/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #999; 3 | } --------------------------------------------------------------------------------