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 e7a1ce6

Browse files
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

‎.htaccess

Lines changed: 5 additions & 0 deletions
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>

‎app/.htaccess

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Options -Indexes

‎app/bootstrap.php

Lines changed: 5 additions & 0 deletions
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';

‎app/controllers/Pages.php

Lines changed: 18 additions & 0 deletions
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+
}

‎app/libraries/Controller.php

Whitespace-only changes.

‎app/libraries/Core.php

Lines changed: 62 additions & 0 deletions
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+
}

‎app/libraries/Database.php

Whitespace-only changes.

‎public/.htaccess

Lines changed: 8 additions & 0 deletions
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>

‎public/css/style.css

Whitespace-only changes.

‎public/index.php

Lines changed: 5 additions & 0 deletions
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;

0 commit comments

Comments
(0)

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