How can a View-Controller approach be implemented in PHP to handle the logic of data presentation?

To implement a View-Controller approach in PHP to handle the logic of data presentation, you can create separate files for the view and controller. The controller will handle the business logic and interact with the model, while the view will handle the presentation of data to the user. This separation of concerns helps to maintain clean and organized code.

// Controller file (controller.php)
class Controller {
    public function getData() {
        // Business logic to fetch data from the model
        $data = Model::getData();
        
        // Pass data to the view
        View::render($data);
    }
}

// View file (view.php)
class View {
    public static function render($data) {
        // Presentation logic to display data to the user
        foreach($data as $item) {
            echo $item . "<br>";
        }
    }
}

// Model file (model.php)
class Model {
    public static function getData() {
        // Data retrieval logic
        return ['Data 1', 'Data 2', 'Data 3'];
    }
}

// Implementing the View-Controller approach
$controller = new Controller();
$controller->getData();