Skip to content

Commit 648d002

Browse files
committed
Added examples
1 parent fe12d19 commit 648d002

File tree

6 files changed

+57
-7
lines changed

6 files changed

+57
-7
lines changed

component/footer.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
</body>
1+
</div>
2+
</div>
3+
</body>
24
</html>

component/head.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,27 @@
33
<head>
44
<title><?= isset($pageTitle) ? $pageTitle : "404 - Page Not Found"; ?></title>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
68
</head>
7-
<body>
9+
<body class="bg-light">
10+
11+
<div class="container my-5">
12+
<div class="row row-cols-1 row-cols-md-3">
13+
<div class="col">
14+
<div class="d-block position-relative p-5 text-start shadow bg-white">
15+
<h1 class="h4">About this script</h1>
16+
<p>Simple, direct and efficient page router created with just PHP and .htaccess</p>
17+
<p>All requests are redirected to <code>index.php</code> with the help of the <code>.htaccess</code>.<br>
18+
The <code>controller/controller.router.php</code> will render the current page<br>(based on the first value of <code>$_SERVER["QUERY_STRING"]</code>).</p>
19+
<p>This allows us to have pretty urls like <code>wordpress</code></p>
20+
</div>
21+
</div>
22+
<div class="col">
23+
<div class="d-block position-relative p-5 text-start shadow bg-white">
24+
<p>Try the following links: </p>
25+
<a href="http://localhost/basic-php-router/home/" class="btn btn-sm btn-primary px-4 py-2 mb-2 me-1">Home Page</a>
26+
<a href="http://localhost/basic-php-router/about/" class="btn btn-sm btn-primary px-4 py-2 mb-2 me-1">About Page</a>
27+
<a href="http://localhost/basic-php-router/a-404-page-or-somethin-random/" class="btn btn-sm btn-primary px-4 py-2 mb-2 me-1">A 404 Page</a>
28+
</div>
29+
</div>

controller/controller.router.php

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public function renderPage()
3232
$pageTitle = "Home Page";
3333
require_once "page/home.php";
3434
break;
35+
case "about":
36+
$pageTitle = "about Page";
37+
require_once "page/about.php";
38+
break;
3539
default:
3640
require_once "page/404.php";
3741
}

page/404.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<?php
22

3-
require_once 'component/head.php';
4-
echo '<p>Hi, all 404 page goes here. Cool right?</p>';
3+
require_once 'component/head.php'; ?>
4+
5+
<div class="col">
6+
<div class="d-block position-relative p-5 text-start shadow bg-white">
7+
<p>This is a <b>404</b> page! Routes not defined on <code>controller/controller.router.php</code> <code>renderPage()</code> will redirect here!</p>
8+
</div>
9+
</div>
10+
<?php
11+
512
require_once 'component/footer.php';
613

714
/* EoF */

page/about.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php require_once 'component/head.php'; ?>
2+
<div class="col">
3+
<div class="d-block position-relative p-5 text-start shadow bg-white">
4+
<p>This is the <b>about</b> page!</p>
5+
</div>
6+
</div>
7+
8+
<?php
9+
require_once 'component/footer.php';
10+
11+
/* EoF */

page/home.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
<?php
1+
<?php require_once 'component/head.php'; ?>
2+
<div class="col">
3+
<div class="d-block position-relative p-5 text-start shadow bg-white">
4+
<p>This is the <b>home</b> page!</p>
5+
</div>
6+
</div>
27

3-
require_once 'component/head.php';
4-
echo '<p>'.$variable.'</p>';
8+
<?php
59
require_once 'component/footer.php';
610

711
/* EoF */

0 commit comments

Comments
 (0)