I will present in this article a easy way to separate PHP code from HTML code using Model-View-Controller pattern, almost all PHP MVC frameworks implement this, at the beginning of PHP was common to interpolate PHP code with HTML code, the PHP code runs on server and generate HTML code.
.htacces redirects all requests to index.php.
What is doing the following request: http://localhost/forecast/index ?
It is searching the class forecast in the controllers folder if exists creates object forecast, after that checks if exists method index and invokes it, this is a basic implementation of routing in a common MVC frameworks.
Root of web application has the following structure:
The complete code could you find on GitHub: https://github.com/adavidoaiei/Model-View-Controller-Pattern