Skip to content

Commit

Permalink
Added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jpneey committed Apr 26, 2021
1 parent fe12d19 commit 648d002
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 7 deletions.
4 changes: 3 additions & 1 deletion component/footer.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
</body>
</div>
</div>
</body>
</html>
24 changes: 23 additions & 1 deletion component/head.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,27 @@
<head>
<title><?= isset($pageTitle) ? $pageTitle : "404 - Page Not Found"; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<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">
</head>
<body>
<body class="bg-light">

<div class="container my-5">
<div class="row row-cols-1 row-cols-md-3">
<div class="col">
<div class="d-block position-relative p-5 text-start shadow bg-white">
<h1 class="h4">About this script</h1>
<p>Simple, direct and efficient page router created with just PHP and .htaccess</p>
<p>All requests are redirected to <code>index.php</code> with the help of the <code>.htaccess</code>.<br>
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>
<p>This allows us to have pretty urls like <code>wordpress</code></p>
</div>
</div>
<div class="col">
<div class="d-block position-relative p-5 text-start shadow bg-white">
<p>Try the following links: </p>
<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>
<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>
<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>
</div>
</div>
4 changes: 4 additions & 0 deletions controller/controller.router.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function renderPage()
$pageTitle = "Home Page";
require_once "page/home.php";
break;
case "about":
$pageTitle = "about Page";
require_once "page/about.php";
break;
default:
require_once "page/404.php";
}
Expand Down
11 changes: 9 additions & 2 deletions page/404.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<?php

require_once 'component/head.php';
echo '<p>Hi, all 404 page goes here. Cool right?</p>';
require_once 'component/head.php'; ?>

<div class="col">
<div class="d-block position-relative p-5 text-start shadow bg-white">
<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>
</div>
</div>
<?php

require_once 'component/footer.php';

/* EoF */
11 changes: 11 additions & 0 deletions page/about.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php require_once 'component/head.php'; ?>
<div class="col">
<div class="d-block position-relative p-5 text-start shadow bg-white">
<p>This is the <b>about</b> page!</p>
</div>
</div>

<?php
require_once 'component/footer.php';

/* EoF */
10 changes: 7 additions & 3 deletions page/home.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php
<?php require_once 'component/head.php'; ?>
<div class="col">
<div class="d-block position-relative p-5 text-start shadow bg-white">
<p>This is the <b>home</b> page!</p>
</div>
</div>

require_once 'component/head.php';
echo '<p>'.$variable.'</p>';
<?php
require_once 'component/footer.php';

/* EoF */

0 comments on commit 648d002

Please sign in to comment.