What is the equivalent of Master Page and Web User Control in PHP?
Assume that I have some advertisments that I want to put in specific area of my pages. In ASP.NET I would use Web User Control for this pupose. What about in PHP? The same question for Master 开发者_如何学GoPage.
The "master page" and "web user control" are classes that are specifically provided by the ASP.NET framework. Just as these capabilities are not native to the languages of Visual Basic or C#, neither are they native to language of PHP - they must implemented on a framework level.
You could certainly do it yourself, however if you're looking for an ASP.NET-like experience in PHP then I suggest you look at the Prado framework, which is very similar and implements many of the features that you've probably used.
There is no such concepts in PHP. I think that it may have some frameworks that implement it, but I don't know wich. Or you can code it by your own :)
I suppose you could do it by putting them in include tags or required
e.g:
<?php
include ('global/header.php');
//Main content goes here
include ('global/main-right.php'); //Adverts or such
include ('global/footer.php');
?>
Where global is a folder containing files used on several pages
There is nothing similar, but you can implement such feature yourself, create header, footer, sidebar and... pages and in other pages include them.
One PHP project that does this well is PPI.
Here is an example of your "master template" which is has historically been named template.php
Folder: https://github.com/dragoonis/ppi-skeleton-app/tree/master/App/View/default/
File: https://github.com/dragoonis/ppi-skeleton-app/tree/master/App/View/default/template.php
If you look at line 28 you'll see the footer content. So say you wanted your widget/"web user control" to be in the footer then you can simply add
include($viewDir . 'controls/footer_control.php');
It's that simple, and will be included in every page load.
Good luck with your search,
Regards, Paul Dragoonis.
精彩评论