Tipo questo:
index.php
<?php
// include the base controller
include 'Controller.php';
// split the request URI into parts
$request = explode('/', $_SERVER['REQUEST_URI']);
$controller = $request[0] ?: 'home'; // home is default
$action = $request[1] ?: 'index'; // index is default action
$otherAction = $request[2] ?: null; // whatever you want
// build the controller we need to instantiate
$controller_name = ucfirst($controller) . 'PageController';
// check it exists
if (file_exists($controllerName)) {
include_once $controllerName . '.php';
} else {
// some pretty 404 page
die('404');
}
// instantiate the controller
$controller = new $controller();
// execute the action
$controller->doAction($action, $otherAction);
Controller.php
<?php
class Controller
{
public function doAction($action, $otherAction)
{
if (method_exists($this, $action)) {
return $this->{$action}($otherAction);
}
die('404 - Page Not Found');
}
}
HomePageController.php
<?php
class HomePageController extends Controller
{
public function index()
{
echo 'Hello World';
exit;
}
}
Quindi andando in
http://localhos non mi esce hello world ma altri errori.
qualcuno puo aiutarmi? se si puo creare un action? grazie