55 lines
1.0 KiB
PHP
55 lines
1.0 KiB
PHP
<?php
|
||
|
||
spl_autoload_register(function ($class_name) {
|
||
$dir = ['/app/controller'];
|
||
foreach ($dir as $path) {
|
||
$path = __DIR__ . $path . $class_name . '.php';
|
||
include $path;
|
||
}
|
||
});
|
||
|
||
var_dump($_SERVER['REQUEST_URI']);
|
||
$uri = trim($_SERVER['REQUEST_URI'], '/');
|
||
|
||
$mass_uri = explode('/', $uri);
|
||
var_dump($mass_uri);
|
||
|
||
$controller = $mass_uri[0];
|
||
$action = $mass_uri[1] ? $mass_uri[1] : 'index';
|
||
$nameClassController = ucfirst($controller) . 'Controller';
|
||
|
||
$cntr = new $nameClassController;
|
||
$cntr->$action();
|
||
|
||
|
||
|
||
class MainModel
|
||
{
|
||
public function getData()
|
||
{
|
||
return [
|
||
'title' => 'Main Page',
|
||
'h3' => 'С новым годом!'
|
||
];
|
||
}
|
||
}
|
||
class MainController
|
||
{
|
||
public function index()
|
||
{
|
||
$model = new MainModel();
|
||
$view = new MainView();
|
||
$result = $model->getData();
|
||
$view->render($result, 'main.tpl');
|
||
}
|
||
}
|
||
class MainView
|
||
{
|
||
public function render($data, $tmpl)
|
||
{
|
||
var_dump($data);
|
||
}
|
||
}
|
||
|
||
$cont = new Route('');
|