The Controller

In KISSMVC, the Controller looks at the HTTP Request and then route the program control to the appropriate function.
It allows the use of Search Engine Friendly URLs on your web application.
Note: For the Controller to work, mod_rewrite is required and has to be configured via the webserver config file or via an .htaccess file.

The KISSMVC Controller achieves the above by doing these:

  1. Parse the HTTP Request URL
  2. Includes a php file based on (1)
  3. Calls a php function included from (2)

Some examples:


http://example.com/controller/action/param1/param2
With the above URL, KISSMVC includes a file controller/action.php and calls the function _action(param1,param2)

http://example.com/controller2/action2
With the above URL, KISSMVC includes a file controller2/action2.php and calls the function _action2()

http://example.com/controller2/action2/
With the above URL, KISSMVC includes a file controller2/action2.php and calls the function _action2('')

http://example.com/controller/action/param1/?a=1&b=2
With the above URL, KISSMVC includes a file controller/action.php and calls the function _action(param1,'?a=1&b=2')
The querystring works and the global variable $_GET = array('a'=>1, 'b'=>2). Your function does not have to define the second parameter.

This is how the Controller is called:

$controller = new Controller('../app/controllers/','/','main','index'); $controller->parse_http_request()->route_request();