- Seme Framework
- versi 4.0.3 (ID)
- Persyaratan
- Download & Install
- Pengaturan
- Tutorial
- Perutean URI
- Konstanta
- Variabel Global
- Model
- View
- Controller
- Library
- CLI (command line interface)
- Core
Create Not found page
The "Not Found" page is a designed page to handle fallback when the requested URL does not exist or is not found in app/controller. In this tutorial, we will create a Not Found page using MaterializeCSS design. Therefore, make sure to complete Tutorial Part 2 on Introduction before proceeding with this tutorial. So that the view settings, view components, as well as themes have been set up and are running smoothly.
Create HTML Layout
First, we will create a special layout for the Not Found page.
Usually, this Not Found page has a different HTML structure compared to other pages, so it should have a special layout.
Create a new file in app/view/front/layout/error_404.php
for the Not Found layout.
<!DOCTYPE html>
<html>
<?php $this->getThemeElement('layout/partials/head', $__forward) ?>
<body style="background-color: khaki;">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1><small style="color: rgba(0,0,0,0.5);">Error 404</small> Notfound</h1>
<p>Oops, looks like this page doesn't exist</p>
<hr>
<h5>Back to <a href="<?=base_url()?>">Homepage</a></h5>
</div>
</div>
</div>
<!-- jQuery, Bootstrap.js, jQuery plugins and Custom JS code -->
<?php $this->getJsFooter(); ?>
<!-- Load and execute javascript code used only in this page -->
<script>
$(document).ready(function(e){
<?php $this->getJsReady(); ?>
});
<?php $this->getJsContent(); ?>
</script>
</body>
</html>
Adjusment for Notfound controller
After we created the html layout. Now, we need to create or edit the notfound controller at app/controller/notfound.php
.
<?php
/**
* Controller class for throw 404 response code
*
* @package SemeFramework
* @since SemeFramework 1.0
*
* @codeCoverageIgnore
*/
class NotFound extends \SENE_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$data = array();
header("HTTP/1.0 404 Not Found");
$this->setTheme('front');
$this->setTitle('Notfound - Error 404');
$this->loadLayout("error_404",$data);
$this->render();
}
}
Test the notfound page
To test the notfound page that we have created before. We can test it using randomized url after the base_url. As you can see on this example below:
http://localhost/seme_framework/asdasdasad