There is such code:

index.php:

<?php // Подключаем загрузчик приложений в единую точку входа require_once 'app/load.php'; ?> 

routing.php:

 <?php class Routing { static function execute() { // контроллер и действие по умолчанию $controller_name = 'Main'; $action_name = 'index'; $routes = explode('/', $_SERVER['REQUEST_URI']); $model_name = 'Model_'.$controller_name; $controller_name = 'Controller_'.$controller_name; $action_name = 'action_'.$action_name; $controller_file = strtolower($controller_name).'.php'; $controller_path = "core/".$controller_file; if(file_exists($controller_path)) { include $controller_path; } // создаем контроллер $controller = new $controller_name; $action = $action_name; } } ?> 

load.php:

 <?php require_once 'core/routing.php'; require_once 'core/model.php'; require_once 'core/view.php'; require_once 'core/controller.php'; //Запуск роутинга Routing::execute(); ?> 

controller.php:

 <?php class Controller { public $model; public $view; function __construct() { $this -> view = new View(); } } ?> 

controller_main.php:

 <?php class Controller_Main extends Controller { function action_index() { $this -> view -> generate('fgdfgdfgdfg', 'template.php'); } } ?> 

view.php:

 <?php class View { function generate($content, $template, $data = null) { include 'app/views/template.php'; } } ?> 

template.php:

 <?php echo $content; ?> 

The problem is that it is not clear how to display the text correctly. It is now empty.

    1 answer 1

    I wonder what you wanted to achieve by declaring a copy of the class, but not turning to it?)

     $controller = new $controller_name; $action = $action_name; 

    You have $controller_name - your instance of Controller_Main , which contains the action_index() method. Viyushka is collected, but not displayed, because you did not use this method. You can write in your Routing at the end so $controller -> $action();

    And the second action_index() in the class Controller Why do you?

    • action_index() in the class Controller superfluous. Made the edit. - Ilnyr