简体   繁体   English

在PHP中替代ASP.NET的UserControls?

[英]Alternative of ASP.NET's UserControls in PHP?

I have developed many web applications in ASP.NET in which I have make use of UserControls to manage header footer and any other common part of a web page. 我在ASP.NET中开发了许多Web应用程序,我在其中使用UserControl来管理页眉和页面的任何其他常见部分。 Now I am developing an app in PHP, is there anything which I can use as an alternative of UserControls?? 现在我正在用PHP开发一个应用程序,有什么我可以用作UserControls的替代品吗?

How I can implement the similar concept in PHP? 我如何在PHP中实现类似的概念?

Thanks? 谢谢?

A second answer which is a bit harder to explain in detail here, is to build your own 'UserControl' classes. 第二个答案在这里有点难以详细解释,就是建立自己的'UserControl'类。 The Classes would have the neccessary properties that you require, and Would have a RenderHTML() method that would output the control to the screen. Classes将具有您需要的必要属性,并且具有将控件输出到屏幕的RenderHTML()方法。

The UserControl concept does not explicitly exist in PHP, though you can encapsulate the the functionality that you want in a file and use the include() function to place it into your pages where you wish. 尽管您可以在文件中封装所需的功能,然后使用include()函数将其放入您希望的页面中,但UserControl概念并未明确存在于PHP中。

<html>
 <head>
   <title></title>
 </head>
 <body>
   <?php include('header.php'); ?>
   <?php include('pageBody.php'); ?>
   <?php include('footer.php'); ?>
 </body>
</html>

Note that Smarty provides for much better separation of processing and rendering, and will make this type of thing super smooth. 请注意, Smarty提供了更好的处理和渲染分离,并使这种类型的东西超级流畅。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM