Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f145377

Browse files
Connect to database class, Db READ functionality
1 parent f6bc936 commit f145377

File tree

17 files changed

+102
-98
lines changed

17 files changed

+102
-98
lines changed

‎config/credentials.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
define('DB_HOST', 'localhost');
44
define('DB_USER', 'root');
55
define('DB_PASS', '');
6-
define('DB_NAME', 'test');
6+
define('DB_NAME', 'todo_db');

‎config/utilities.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,24 @@ function getUri() : string
1212

1313
return $uri;
1414
}
15-
/**
16-
* Get request method.
17-
* Returns a string.
15+
16+
/**
17+
* Loads a view file
18+
* @param string $view Example: 'index', 'about', 'contact'
19+
* @param array $data Passing vars to the view
20+
* @return void
1821
*/
19-
function getMethod()
20-
{
21-
$method = $_SERVER['REQUEST_METHOD'];
22-
23-
return $method;
22+
function view(string $view, array $data = []) : void
23+
{
24+
$file = APPROOT . '/src/views/' . $view . '.php';
25+
// Check for view file
26+
if (is_readable($file))
27+
{
28+
require_once $file;
29+
}
30+
else
31+
{
32+
// View does not exist
33+
die('<h1> 404 Page not found </h1>');
34+
}
2435
}

‎src/controllers/Controller.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

‎src/controllers/Folder1/Class1.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
22
namespace Controllers\Folder1;
33

4-
use \Controllers\Controller;
5-
64
/**
75
* ModuleClass file
86
* For example for large projects with many folders (modules)
97
*/
10-
class Class1extends Controller
8+
class Class1
119
{
1210
public function index()
1311
{

‎src/controllers/Folder1/Class2.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
22
namespace Controllers\Folder1;
33

4-
use \Controllers\Controller;
5-
64
/**
75
* ModuleClass file
86
* For example for large projects with many folders (modules)
97
*/
10-
class Class2extends Controller
8+
class Class2
119
{
1210
public function index($data)
1311
{

‎src/controllers/Folder2/Class1.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
22
namespace Controllers\Folder2;
33

4-
use \Controllers\Controller;
5-
64
/**
75
* ModuleClass file
86
* For example for large projects with many folders (modules)
97
*/
10-
class Class1extends Controller
8+
class Class1
119
{
1210
public function index()
1311
{

‎src/controllers/Folder2/Class2.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
22
namespace Controllers\Folder2;
33

4-
use \Controllers\Controller;
5-
64
/**
75
* ModuleClass file
86
* For example for large projects with many folders (modules)
97
*/
10-
class Class2extends Controller
8+
class Class2
119
{
1210
public function index($data)
1311
{

‎src/controllers/Index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22
namespace Controllers;
33

4-
class Indexextends Controller
4+
class Index
55
{
66
public function home()
77
{
8-
Controller::view('Index/home');
8+
view('Index/home');
99
}
1010

1111
public function about()
1212
{
13-
Controller::view('Index/about');
13+
view('Index/about');
1414
}
1515
}

‎src/controllers/Tasks.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
namespace Controllers;
3+
4+
use \Models\Task;
5+
6+
class Tasks
7+
{
8+
public function __construct()
9+
{
10+
$this->taskModel = new Task;
11+
}
12+
13+
public function list()
14+
{
15+
$tasks = $this->taskModel->selectAll();
16+
17+
view('TestDb/tasks', $tasks);
18+
}
19+
}

‎src/models/Database.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?php
2+
namespace Models;
3+
4+
use \PDO;
5+
26
/**
37
* PDO Database Class
48
* Connect to database

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /