Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/164268-php-question/
Share on other sites

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'.

Link to comment
https://forums.phpfreaks.com/topic/164268-php-question/#findComment-866536
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/164268-php-question/#findComment-866540
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.