-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f33451f
Showing
16 changed files
with
318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Deny From All |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Deny From All |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
abstract class Koneksi { | ||
protected $koneksi; | ||
|
||
protected function connect() { | ||
$this->koneksi = new mysqli("localhost", "root", "", "login_sekolah"); | ||
return $this->koneksi; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
class Load { | ||
|
||
public static function model(string $string) { | ||
require "./Models/$string.php"; | ||
return new $string(); | ||
} | ||
|
||
public static function view(string $path, $data) { | ||
extract($data, EXTR_PREFIX_SAME, ""); | ||
require "./Views/$path.php"; | ||
} | ||
|
||
public static function public_file(string $path) { | ||
|
||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?php | ||
|
||
class Model extends Koneksi { | ||
|
||
public $conn; | ||
protected $table; | ||
|
||
public function __construct(){ | ||
$this->conn = parent::connect(); | ||
} | ||
|
||
public static function find(int $id) { | ||
$db = new Self; | ||
$db->table = strtolower(get_called_class()); | ||
$res = $db->conn->query("SELECT * FROM $db->table WHERE id='$id'"); | ||
|
||
if($res->num_rows == 1) { | ||
return $res->fetch_object(); | ||
} else { | ||
return []; | ||
} | ||
|
||
} | ||
|
||
public static function get(string $where='') { | ||
$db = new Self; | ||
$db->table = strtolower(get_called_class()); | ||
|
||
$condition = ($where != '') ? "WHERE ".trim($where) : ""; | ||
$res = $db->conn->query("SELECT * FROM $db->table $condition"); | ||
|
||
$result = []; | ||
|
||
while($data = $res->fetch_object()) { | ||
$result[] = $data; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public static function insert(array $data) { | ||
$db = new Self; | ||
$db->table = strtolower(get_called_class()); | ||
|
||
$sql = "INSERT INTO $db->table SET "; | ||
|
||
$a = 0; | ||
foreach($data as $field => $res) { | ||
$sql .= $field . "='" . $db->conn->real_escape_string( $res ) . "'"; | ||
|
||
if($a != count($data)-1) { | ||
$sql .= ", "; | ||
} else { | ||
$sql .= ";"; | ||
} | ||
$a++; | ||
} | ||
|
||
if($res = $db->conn->query($sql)) { | ||
return [ | ||
'data' => $data, | ||
'id' => $db->conn->insert_id, | ||
'message' => 'Success', | ||
'status' => true | ||
]; | ||
} else { | ||
return [ | ||
'data' => $data, | ||
'message' => 'Failed', | ||
'status' => false | ||
]; | ||
} | ||
} | ||
|
||
public static function update(array $data, string $where) { | ||
$db = new Self; | ||
$db->table = strtolower(get_called_class()); | ||
|
||
$sql = "UPDATE $db->table SET "; | ||
|
||
$a = 0; | ||
foreach($data as $field => $res) { | ||
$sql .= $field . "='" . $db->conn->real_escape_string( $res ) . "'"; | ||
|
||
if($a != count($data)-1) { | ||
$sql .= ", "; | ||
} else { | ||
$sql .= " "; | ||
} | ||
$a++; | ||
} | ||
|
||
$sql .= "WHERE " . $where; | ||
if($db->conn->query($sql)) { | ||
return [ | ||
'data' => $data, | ||
'where' => $where, | ||
'message' => 'Success', | ||
'status' => true | ||
]; | ||
} else { | ||
return [ | ||
'data' => $data, | ||
'where' => $where, | ||
'message' => 'Failed', | ||
'status' => false | ||
]; | ||
} | ||
} | ||
|
||
public static function delete(string $where) { | ||
$db = new Self; | ||
$db->table = strtolower(get_called_class()); | ||
|
||
$data = Self::get($where); | ||
if(count($data) > 0) { | ||
$data = $data[0]; | ||
} else { | ||
return [ | ||
'data' => $data, | ||
'where' => $where, | ||
'message' => 'Failed', | ||
'status' => false | ||
]; | ||
} | ||
|
||
$sql = "DELETE FROM $db->table WHERE " . $where; | ||
if($db->conn->query($sql)) { | ||
return [ | ||
'data' => $data, | ||
'where' => $where, | ||
'message' => 'Success', | ||
'status' => true | ||
]; | ||
} else { | ||
return [ | ||
'data' => $data, | ||
'where' => $where, | ||
'message' => 'Failed', | ||
'status' => false | ||
]; | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Deny From All |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class Errors { | ||
public function get404() | ||
{ | ||
echo "404"; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
class Home { | ||
public function api_get() { | ||
header("Content-Type: application/json"); | ||
$mapel = Load::model('Mapel')->get(); | ||
|
||
echo json_encode($mapel); | ||
} | ||
|
||
public function index() { | ||
Load::view('index', [ | ||
'mapel' => Load::model('Mapel')->get(), | ||
'no' => 1 | ||
]); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Deny From All |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
class Dashboard { | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
class Mapel extends Model { | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
class User extends Model { | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Deny From All |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<table border=1 cellspacing=0 cellpadding=10> | ||
|
||
<tr> | ||
<th>No</th> | ||
<th>Nama</th> | ||
</tr> | ||
|
||
<?php foreach($mapel as $field => $res): ?> | ||
<tr> | ||
|
||
<td><?= $no++ ?></td> | ||
<td><?= $res->nama ?></td> | ||
|
||
</tr> | ||
<?php endforeach; ?> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
require "Config/Koneksi.php"; | ||
require "Config/Model.php"; | ||
require "Config/Loader.php"; | ||
require "routes.php"; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
class Route { | ||
public $route_control; | ||
public $route; | ||
public $set404; | ||
|
||
public function __construct($route_param) { | ||
$this->route_control = $route_param; | ||
} | ||
|
||
public function acc404() { | ||
require "./Controllers/Error.php"; | ||
|
||
$control = new Errors(); | ||
$control->get404(); | ||
} | ||
|
||
public function read() { | ||
$cond = false; | ||
foreach($this->route as $path => $controllerPath) { | ||
if($path == $this->route_control) { | ||
$controller = explode("@", $controllerPath); | ||
require "./Controllers/$controller[0]".".php"; | ||
|
||
$controllerString = $controller[0]; | ||
$methodString = $controller[1]; | ||
|
||
$control = new $controllerString(); | ||
$control->$methodString(); | ||
$cond = true; | ||
break; | ||
} else { | ||
continue; | ||
} | ||
} | ||
|
||
if(!$cond) { | ||
$this->acc404(); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
$route = isset($_GET['page']) ? $_GET['page'] : "default"; | ||
|
||
$r = new Route($route); | ||
$r->route['default'] = "Home@index"; | ||
$r->route['api.mapel'] = "Home@api_get"; | ||
|
||
$r->set404 = "Error@get404"; | ||
$r->read(); | ||
|
||
|
||
?> |