Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit a345734

Browse files
committed
update package twig for templating
1 parent 7890109 commit a345734

File tree

9 files changed

+57
-27
lines changed

9 files changed

+57
-27
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
* saya sering melakukan update pada repo, saya sarankan untuk melakukan
2525
git pull jika terdapat ada update ahahaha
2626

27+
<!-- update -->
28+
#### Update
29+
* saya sedang development untuk implementation template engine menggunakan twig dari syphony
30+
[ **Documentasi Resmi Twig 3.x** ](https://twig.symfony.com/doc/3.x/)
31+
2732
<!-- table of content -->
2833
## Daftar isi Content
2934

apps/config/constant.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
# base-url untuh path
5151
define('BASEURL', $configuration['APP_HOST'] . $configuration['APP_NAME'] . '/');
5252

53+
# root core
54+
define('_ROOT_VIEW', 'apps/views/');
55+
define('_ROOT_MODEL', 'apps/models/');
56+
define('_ROOT_ERROR_VIEW', 'apps/error/pages/');
57+
5358
/**
5459
* ----------------------------------------------------------------------------------------------
5560
* Constant in debelopment

apps/config/functions.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,18 @@ function view($view = '', $data = [])
235235
{
236236
// mengarah pada folder apps/views/ namaviews.php
237237
try {
238-
if (!file_exists('apps/views/' . $view . '.php')) {
238+
if (!file_exists(_ROOT_VIEW . $view . '.php')) {
239239
throw new Exception("View ". $view ." Not Found. Check Controllernya Bro");
240240
}else{
241-
require_once 'apps/views/' . $view . '.php';
242-
// return true;
241+
242+
# comment this jika tidak ingin menggunakan twig engine
243+
// $loader = new \Twig\Loader\FilesystemLoader(_ROOT_VIEW);
244+
// $twig = new \Twig\Environment($loader, ['debug' => true]);
245+
246+
// echo $twig->render($view . '.php' , $data);
247+
248+
# uncomment this jika tidak ingin menggunakan twig engine
249+
require_once _ROOT_VIEW . $view . '.php'; //update template engine menggunakan twig
243250
}
244251
return false;
245252
} catch (Exception $exception) {
@@ -257,11 +264,11 @@ function model($model = '')
257264
{
258265
// mengarah pada folder apps/models/ namamodels.php
259266
try {
260-
if (!file_exists('apps/models/' . $model . '.php')) {
267+
if (!file_exists(_ROOT_MODEL . $model . '.php')) {
261268
throw new Exception("Models ". $model ." Not Found. Check Controllernya Bro di bagian load modelnya ");
262269
}
263270

264-
require_once 'apps/models/' . $model . '.php';
271+
require_once _ROOT_MODEL . $model . '.php';
265272
return new $model;
266273
} catch (Exception $exception) {
267274
$my_error = new Error_Handling;

apps/core/Controller.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,18 @@ public static function view($view = '', $data = [])
3939
{
4040
// mengarah pada folder apps/views/ namaviews.php
4141
try {
42-
if (!file_exists('apps/views/' . $view . '.php')) {
42+
if (!file_exists(_ROOT_VIEW . $view . '.php')) {
4343
throw new Exception("View ". $view ." Not Found. Check Controllernya Bro");
4444
}
4545

46-
require_once 'apps/views/' . $view . '.php';
46+
# comment this jika tidak ingin menggunakan twig engine
47+
// $loader = new \Twig\Loader\FilesystemLoader(_ROOT_VIEW);
48+
// $twig = new \Twig\Environment($loader, ['debug' => true]);
49+
50+
// echo $twig->render($view . '.php' , $data);
51+
52+
# uncomment this jika tidak ingin menggunakan twig engine
53+
require_once _ROOT_VIEW . $view . '.php'; //update template engine menggunakan twig
4754
exit;
4855
} catch (Exception $exception) {
4956
$my_error = new Error_Handling;
@@ -62,11 +69,11 @@ public static function model($model = '')
6269
// mengarah pada folder apps/models/ namamodels.php
6370

6471
try {
65-
if (!file_exists('apps/models/' . $model . '.php')) {
72+
if (!file_exists(_ROOT_MODEL . $model . '.php')) {
6673
throw new Exception("Models ". $model ." Not Found. Check Controllernya Bro di bagian load modelnya ");
6774
}
6875

69-
require_once 'apps/models/' . $model . '.php';
76+
require_once _ROOT_MODEL . $model . '.php';
7077
return new $model;
7178
exit;
7279
} catch (Exception $exception) {
@@ -86,10 +93,12 @@ public static function error_view($view = '', $data = [])
8693
// mengarah pada folder apps/error/pages/ namaviews.php
8794
try {
8895

89-
if(!file_exists('apps/error/pages/' . $view . '.php')){
96+
if(!file_exists(_ROOT_ERROR_VIEW . $view . '.php')){
9097
throw new Exception("views ". $view ." Not Found. Check Controllernya Bro di bagian load view-nya ");
9198
}
92-
require_once 'apps/error/pages/' . $view . '.php';
99+
100+
require_once _ROOT_ERROR_VIEW . $view . '.php';
101+
93102

94103
} catch (\Throwable $exception) {
95104
$my_error = new Error_Handling;

apps/init.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
include 'config/config.php';
4949

5050

51+
5152
// spl autoload php atau bootstrap loading classname pada folder core
5253
spl_autoload_register(function ($class) {
5354
$class = explode("\\", $class);
@@ -86,4 +87,4 @@
8687
require_once __DIR__ . '/api/' . $class . '.php';
8788
}
8889
return false;
89-
});
90+
});

apps/routes/Web.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public function __construct()
5555
$router = new Router();
5656

5757
#custom 404 header un-commnet baris berikut
58-
// $router->set404(function() {
59-
// header('HTTP/1.1 404 Not Found');
60-
// redirect_404();
61-
// });
58+
$router->set404(function() {
59+
header('HTTP/1.1 404 Not Found');
60+
redirect_404();
61+
});
6262

6363

6464
// your route here

apps/views/Welcome.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
font-size: 50px;
9595
}
9696

97-
.links>a {
97+
.links> li a {
9898
display: inline-block;
9999
padding-top: 2vh;
100100
color: #e1eaf9;
@@ -160,16 +160,16 @@
160160
</div>
161161
</div>
162162
<div class="row">
163-
<div class="col-3">
163+
<div class="col-5">
164164
<ul type="none" class="links" >
165-
<a href="https://naagaraa.github.io/documentation-mini-mvc-php-project/" target="_blank" ><li>DOCUMENTATION</li></a>
166-
<a href="https://github.com/naagaraa/mini-mvc-phpnative" target="_blank"><li>GITHUB</li></a><br>
167-
<a href="https://www.youtube.com/playlist?list=PLK5_CL-hAKCf-H7snj3RlLVjrkJ7yql6o" target="_blank"><li>YOUTUBE</li></a>
168-
<a href="https://www.instagram.com/naagaraa/" target="_blank"><li>INSTAGRAM</li></a>
169-
<a href="https://dribbble.com/naagaraa/" target="_blank"><li>DRIBBLE</li></a><br>
170-
<a href="<?= url('info') ?>" target="_blank"><li>PHP INFO</li></a>
171-
<a href="<?= url('login') ?>" ><li>Login Page</li></a>
172-
<a href="<?= url('register') ?>" ><li>Register Page</li></a>
165+
<li><a href="https://naagaraa.github.io/documentation-mini-mvc-php-project/" target="_blank" >DOCUMENTATION</a></li>
166+
<li><a href="https://github.com/naagaraa/mini-mvc-phpnative" target="_blank">GITHUB</a></li>
167+
<li><a href="https://www.youtube.com/playlist?list=PLK5_CL-hAKCf-H7snj3RlLVjrkJ7yql6o" target="_blank">YOUTUBE</a></li>
168+
<li><a href="https://www.instagram.com/naagaraa/" target="_blank">INSTAGRAM</a></li>
169+
<li><a href="https://dribbble.com/naagaraa/" target="_blank">DRIBBLE</a></li>
170+
<li><a href="<?= url('info') ?>" target="_blank">PHP INFO</a></li>
171+
<li><a href="<?= url('login') ?>" >Login Page (Stisla)</a></li>
172+
<li><a href="<?= url('register') ?>" >Register Page (Stisla)</a></li>
173173
</ul>
174174
</div>
175175
</div>

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
"mpdf/mpdf": "^8.0",
2626
"phpmailer/phpmailer": "^6.2",
2727
"phpoffice/phpspreadsheet": "^1.14",
28+
"twig/twig": "3.0",
2829
"vlucas/phpdotenv": "^5.2"
2930
},
3031
"require-dev": {
3132
"php": ">=7.3.2",
3233
"bramus/router": "~1.5",
3334
"phpmailer/phpmailer": "^6.2",
34-
"vlucas/phpdotenv": "^5.2"
35+
"vlucas/phpdotenv": "^5.2",
36+
"twig/twig": "3.0"
3537
},
3638
"config": {
3739
"optimize-autoloader": true,

index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
7777
$dotenv->load();
7878

79+
7980
require 'system/_init.php';
8081
require_once 'apps/init.php';
8182

0 commit comments

Comments
 (0)