Generally the parameters in the urls are used to call a respective class/function
. Let say we have these urls:
- example.com/index.php?controller=foo
- example.com/index.php?controller=foo&function=edit
- example.com/index.php?controller=bar
At index.php
you could start playing with includes like below:
$controller = $_GET["controller"];
include("controllers/{$controller}");
$theClass = new $controller();
Some web applications work with a "default funcion" that is triggered when a function is not specified in the url. For example, an index
function:
$function = $_GET["function"];
if (empty($function))
$function = "index"; // the default function to be called
$theClass->$function();
The Foo class can looks like this:
class Foo{
function index(){
echo "hello index";
}
function edit(){
echo "editing foo";
}
}
- For the url example.com/index.php?controller=foo the output will be
hello index
- For the url example.com/index.php?controller=foo&function=edit the output will be
editting foo
Note:
You can use $_SERVER['QUERY_STRING']
instead $_GET
to give urls more "friendly".