What are best practices for separating the View from Controllers in PHP MVC architecture?

In PHP MVC architecture, it is essential to separate the View from Controllers to maintain clean and organized code. One common best practice is to use templates or views to handle the presentation logic separately from the business logic in the controllers. This separation allows for easier maintenance, testing, and reusability of code.

// Controller
class Controller {
    public function index() {
        $data = ['name' => 'John Doe'];
        $view = new View();
        $view->render('index', $data);
    }
}

// View
class View {
    public function render($template, $data) {
        extract($data);
        include 'views/' . $template . '.php';
    }
}

// index.php
$controller = new Controller();
$controller->index();