Skip to content

Commit e7a1ce6

Browse files
committed
Initial commit: core framework files
0 parents  commit e7a1ce6

File tree

11 files changed

+104
-0
lines changed

11 files changed

+104
-0
lines changed

Diff for: .htaccess

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<IfModule mod_rewrite.c>
2+
RewriteEngine On
3+
RewriteRule ^$ public/ [L]
4+
RewriteRule (.*) public/$1 [L]
5+
</IfModule>

Diff for: app/.htaccess

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Options -Indexes

Diff for: app/bootstrap.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
// Load libraries
3+
require_once 'libraries/Core.php';
4+
require_once 'libraries/Controller.php';
5+
require_once 'libraries/Database.php';

Diff for: app/controllers/Pages.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
class Pages
3+
{
4+
public function __construct()
5+
{
6+
7+
}
8+
9+
public function index()
10+
{
11+
12+
}
13+
14+
public function about($id)
15+
{
16+
echo $id;
17+
}
18+
}

Diff for: app/libraries/Controller.php

Whitespace-only changes.

Diff for: app/libraries/Core.php

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* App Core Class
4+
* Creates URL & loads core controller
5+
* URL format - /controller/method/params
6+
*/
7+
class Core
8+
{
9+
protected $currentController = 'Pages';
10+
protected $currentMethod = 'index';
11+
protected $params = [];
12+
13+
public function __construct()
14+
{
15+
//var_dump($this->getUrl());
16+
$url = $this->getUrl();
17+
18+
// Look in controllers for first value
19+
if (file_exists('../app/controllers/' . ucwords($url[0]) . '.php'))
20+
{
21+
// If exists, set as controller
22+
$this->currentController = ucwords($url[0]);
23+
// Unset 0 Index
24+
unset($url[0]);
25+
}
26+
27+
// Require the controller
28+
require_once '../app/controllers/' . $this->currentController . '.php';
29+
30+
// Instantiate controller class
31+
$this->currentController = new $this->currentController;
32+
33+
// Check for second part of URL
34+
if (isset($url[1]))
35+
{
36+
// Check to see if method exists in controller
37+
if (method_exists($this->currentController, $url[1]))
38+
{
39+
$this->currentMethod = $url[1];
40+
// Unset 1 Index
41+
unset($url[1]);
42+
}
43+
}
44+
45+
// Get params
46+
$this->params = $url ? array_values($url) : [];
47+
48+
// Call a callback with array of params
49+
call_user_func_array([$this->currentController, $this->currentMethod], $this->params);
50+
}
51+
52+
public function getUrl()
53+
{
54+
if (isset($_GET['url']))
55+
{
56+
$url = rtrim($_GET['url'], '/');
57+
$url = filter_var($url, FILTER_SANITIZE_URL);
58+
$url = explode('/', $url);
59+
return $url;
60+
}
61+
}
62+
}

Diff for: app/libraries/Database.php

Whitespace-only changes.

Diff for: public/.htaccess

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<IfModule mod_rewrite.c>
2+
Options -Multiviews
3+
RewriteEngine On
4+
RewriteBase /php-basic-mvc/public
5+
RewriteCond %{REQUEST_FILENAME} !-d
6+
RewriteCond %{REQUEST_FILENAME} !-f
7+
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
8+
</IfModule>

Diff for: public/css/style.css

Whitespace-only changes.

Diff for: public/index.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
require_once '../app/bootstrap.php';
3+
4+
// Init Core Library
5+
$init = new Core;

Diff for: public/js/main.js

Whitespace-only changes.

0 commit comments

Comments
 (0)