[英]How to retrieve multiple files in html link with PHP?
I split up my website using code refactoring with templates. 我使用带有模板的代码重构拆分了我的网站。
When I go to construct a basic link in my nav.php file or I suppose anywhere on the site for that mater, I need to grab multiple files as the site is templated -- let's assume for this example the user is going to services.php. 当我在nav.php文件中构造一个基本链接时,或者我想在网站上的该主机上的任何地方,我都需要在该网站被模板化时抓取多个文件-让我们以本示例为例,假设用户将要使用服务。的PHP。
I believe I would need to attach all of these files in the link: 我相信我需要在链接中附加所有这些文件:
How do I go about constructing a link to accomplish this? 我该如何构建一个链接来完成此任务? Could I make some sort of array and attach all of the files in the link and then loop through the array with a foreach
statement and echo
the results? 我可以制作某种数组并附加链接中的所有文件,然后使用foreach
语句foreach
数组并echo
显结果吗?
You don't grab the other files through the link. 您不会通过链接获取其他文件。 You link to one URL, which processes a single PHP file and that PHP file includes all of the other necessary files. 您链接到一个URL,该URL处理一个PHP文件,并且该PHP文件包括所有其他必要的文件。 For example, your link might be: 例如,您的链接可能是:
<a href="/services.php">Services</a>
Which will run services.php, which will then include the header, nav, footer, etc. For example services.php could look like this: 它将运行services.php,然后将包含标头,导航,页脚等。例如,services.php可能如下所示:
require( "header.php" );
// Some PHP code specific to servicer.php goes here.
require( "nav.php" );
// Some more PHP code specific to servicer.php goes here.
require( "footer.php" );
Using something like Smarty would be a nice and clean way of implemtning views in a MVC setup. 使用诸如Smarty之类的东西将是在MVC设置中实现视图的一种好方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.