What are best practices for structuring PHP code to handle different actions and controllers for a website?

When structuring PHP code to handle different actions and controllers for a website, it is recommended to use a MVC (Model-View-Controller) design pattern. This helps to separate the concerns of data manipulation, presentation, and user input handling. By organizing your code in this way, it becomes easier to maintain, test, and scale your application.

// Example of a simple MVC structure in PHP

// Controller
class Controller {
    public function handleRequest($action) {
        switch($action) {
            case 'home':
                $this->showHome();
                break;
            case 'about':
                $this->showAbout();
                break;
            default:
                $this->show404();
                break;
        }
    }

    public function showHome() {
        // Logic to display the home page
    }

    public function showAbout() {
        // Logic to display the about page
    }

    public function show404() {
        // Logic to display a 404 page
    }
}

// Usage
$controller = new Controller();
$action = isset($_GET['action']) ? $_GET['action'] : 'home';
$controller->handleRequest($action);