Why does the PHP framework controller layer load a file with a .tpl suffix? I wrote
<?php
echo $name; //居然能输出正确的值
//Question, why can files with .tpl suffix also be able to execute PHP scripts? Isn’t it possible to parse PHP only by using .PH files?
某草草2017-05-16 17:08:08
The PHP interpreter only cares about the file content, it doesn’t care what the extension is
Require/include other files in the code in one compilation and run cycle, instead of opening a new interpreter every time you open a new file
In order to easily distinguish it from other files, a certain extension will be configured on the web server to send to PHP. This is only a restriction on the entry file. After running, what is required/included later has nothing to do with this configuration. If this is not done, , whatever file type it becomes will be sent to PHP for review. This is unrealistic due to performance and security considerations (in other words, you need to treat PHP and the web server independently)
For example
For nginx, it is
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/var/run/php.socket;
fastcgi_index index.php;
include fastcgi.conf;
}
For apache, that is
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
In fact, you can change it to any extension you want, or even match it completely (of course, it is not recommended to do this)
淡淡烟草味2017-05-16 17:08:08
The framework itself loads the .tpl file and parses it into php code. It's like you load an xml file with php and then parse the xml and output it. What I said isn't quite accurate, but it's about the same meaning.
大家讲道理2017-05-16 17:08:08
This is a template file
You can check out the introduction of smarty template