PHP Classes

File: ctr.php

Recommend this page to a friend!
  Classes of Bastian Neumann   Rewriter   ctr.php   Download  
File: ctr.php
Role: Example script
Content type: text/plain
Description: Sample Script
Class: Rewriter
Rewrite request variables based on the request URI
Author: By
Last change: More Comments, little change in handling
Date: 18 years ago
Size: 1,397 bytes
 

Contents

Class file image Download
<?php
// make sure you have a .htaccess file that points to this file for 404 errors use something like this:
//
// ErrorDocument 404 ctr.php
//
// it isn'T wrong to catch 401 and 403 errors, too


include("rewriter.class.php");

// create rewriter instance use the names set in the class script
$controller = new rewriter();
// parsing the incomming request to the REQUEST array
$REQUEST = $controller->decode($REQUEST_URI);
//tell the clinet that everything is ok and the file was found!
$controller->ok();

// display result for understanding
echo "<pre>";
print_r($REQUEST);
echo
"</pre>";

// now see what happend:
switch($REQUEST['page']) {
// the URI http://localhost/rewriter/first.html moved to one of these results...

 
case "first" :
 
// so this is the page, that is displayed if there is first.html given...
 
echo "First page called"; echo "<br><a href=\"".$controller->encode(array("second"),".html")."\">second</a>";
 break;
 case
"second" : echo "Second page called"; echo "<br><a href=\"".$controller->encode(array("third"),".html")."\">third</a>";break;
 case
"third" : echo "Third page called"; echo "<br><a href=\"".$controller->encode(array("index"),".html")."\">index</a>";break;

 default :
 
// this page is called if there is no 'file' given
 
echo "Default page called"; echo "<br><a href=\"".$controller->encode(array("first"),".html")."\">first</a>";
 break;

}


?>