nepzap2 Posted June 30, 2009 Share Posted June 30, 2009 Hello all, I first want to thank the community for always being able to help me. My question is the following: I have seen various web sites that use a method of (I'm Assuming) templating that I'm not familiar with. Maybe you guys help shed some light on the subject. Let's say you have a simple web site with 3 sections (MySQL) * About * Gallery * Contact Instead of having three different pages. There is one "page" file and an "index" file where layout variables are stored. Then according to what link the user clicks the data will vary. For example, The address bar looks something like this "http://exampleURL/?page=About" Do you know what documentation or book/s I can get my hands on to learn this? Any help is greatly appreciated, Thank You Quote Link to comment https://forums.phpfreaks.com/topic/164268-php-question/ Share on other sites More sharing options...
KevinM1 Posted June 30, 2009 Share Posted June 30, 2009 Hello all, I first want to thank the community for always being able to help me. My question is the following: I have seen various web sites that use a method of (I'm Assuming) templating that I'm not familiar with. Maybe you guys help shed some light on the subject. Let's say you have a simple web site with 3 sections (MySQL) * About * Gallery * Contact Instead of having three different pages. There is one "page" file and an "index" file where layout variables are stored. Then according to what link the user clicks the data will vary. For example, The address bar looks something like this "http://exampleURL/?page=About" Do you know what documentation or book/s I can get my hands on to learn this? Any help is greatly appreciated, Thank You You've sorta got it right. When using a query string (the part after the '?' in the URL), the name/value pair that's passed in is used as a command to the site itself. In this case, the 'page' property that's being sent into the script has a value of 'About'. There are a few ways to implement it, but the idea is the same across the board - the main script (probably index.php) intercepts that name/value pair, parses it, and then fetches the correct data based on the value. It could be something as simple as: $page = $_GET['page']; switch($page) { case 'Home': require_once("home.php"); break; case 'Gallery': require_once("gallery.php"); break; case 'Contact': require_once("contact.php"); break; case 'About': require_once("about.php"); break; default: require_once("default.php"); } Or it could be a relatively complex OOP interaction, where the values passed into the script from the query string are encapsulated as objects, are parsed by other objects, and fetch a multitude of other objects back as the necessary page components. I suggest looking up 'front controller' and perhaps 'page controller'. Quote Link to comment https://forums.phpfreaks.com/topic/164268-php-question/#findComment-866536 Share on other sites More sharing options...
Cosizzle Posted June 30, 2009 Share Posted June 30, 2009 Hey, When you see a "?" within the URL it tends to be a variable being passed from a page. When I build web apps I'll use the $_GET[] method (http://us2.php.net/manual/en/reserved.variables.get.php) which will return that part of the URL. I then create a switch statement (http://us3.php.net/manual/en/control-structures.switch.php) to change the content based on the $_GET[] method. I'll usually have templates that I include depending on the $_GET[]. I personally don't know if this is a good or bad way to do something, but from my experience redundant coding is bad therefor I feel that in most cases for me this works. I think for you, you just need to experiment find out what works for you, theres not a single correct way to do something when building a web application, in the end its how high cohesive and loosely coupled it all is. Quote Link to comment https://forums.phpfreaks.com/topic/164268-php-question/#findComment-866540 Share on other sites More sharing options...
nepzap2 Posted July 1, 2009 Author Share Posted July 1, 2009 Hey guys, Thank you very much. With the information that both of you gave me I have been able to find documentation and tutorials for this concept. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/164268-php-question/#findComment-867077 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.