How does most php web applications parse .phtml files

In most php web applications, you will see they put their presentation layers into .phtml files, which mixes the codes in php and html for a better control of the page view.

So, how do they make the apache or any other server to parse the .phtml files?

The answer is they don’t parse .phtml files directly, they use include statement to include the .phtml file in a .php file.

Most php web applications start with the index.php file. The web server can understand the .php file and it will parse it as php code. When they want to use the code in a .phtml file, they just include the .phtml file and the the code in that .phtml file will simply become part of the the .php file you used to include the .phtml file. Thus, the server doesn’t parse the .phtml file directly, all it does is to parse the code in the php file, and when it sees an include statement for a .phtml file, it includes the code in that .phtml file and then parse them as php code.

If you try to parse .phtml file directly, the server will probably not parsing the file but to put the exact code as it is to the browser.

Another way to parse .phtml files and parse them directly is to add the following to the .htaccess file

AddType application/x-httpd-php .phtml

Search within Codexpedia

Custom Search

Search the entire web

Custom Search