Jump to content

[SOLVED] index.php?view=review&rid=10 vs review.php?id=10


Prodigal Son

Recommended Posts

I'm coding a small database driven site and I have my index.php include the view page and call the database to make queries based on what is in the $_GET variables. So to grab a review with id 10, my url would look like: index.php?view=review&rid=10

 

I see a lot of sites that would have the url look like this instead: review.php?id=10

 

Is that a different coding method altogether?

 

To keep it simple with the first method in my index.php I could have:

-php stuff

-header

--include review.php file

-footer

 

Since the included files will only carry its own individual content if I need to edit the layout I could just change the index page. However the second method I would need to include a header and footer into the content on all pages? If I make some drastic changes and let's say I wouldn't even have a footer anymore or maybe I would need another sub section for the layout, wouldn't I have to go through and edit all the pages? The first method also seems like it would be easier to separate logic and layout across specific pages by grabbing the view get request if needed. Maybe I'm missing some advantages of the second method?

I see a lot of sites that would have the url look like this instead: review.php?id=10

 

Thats the method that I tend to employ, I prefer the neater looking urls. Though personally I tend to have the file in a review folder so that the url would be http://www.mysite.com/review/?id=10 (and thats when I'm not using 'pretty urls' with mod_rewrite). The code structure is basically the opposite of what you have...

 

-php stuff

include 'header.php';

<!-- content of review .php -->

include 'footer';

Thats the method that I tend to employ, I prefer the neater looking urls. Though personally I tend to have the file in a review folder so that the url would be http://www.mysite.com/review/?id=10 (and thats when I'm not using 'pretty urls' with mod_rewrite). The code structure is basically the opposite of what you have...

 

-php stuff

include 'header.php';

<!-- content of review .php -->

include 'footer';

Hmm, using the other way I could easily create a switch statement and have cases for each view and keep stuff like function calls separate from the page. Using this method, how would create a controller type page?

 

Would something like this work:

switch (basename($_SERVER['PHP_SELF'], '.php'))
{
    case 'review':
     run_function($_GET['id']);
    break;
}

I don't understand the question. The whole point of the approach is you eliminate the need for the switch statement because each page is it's own independent page. So you have no need of varying the include based on the requested page.

I don't understand the question. The whole point of the approach is you eliminate the need for the switch statement because each page is it's own independent page. So you have no need of varying the include based on the requested page.

Hmm, the way I learned to code (maybe it was a bad way lol) was that it's better to keep functions separate from the actual page.

 

So let's say I have 5 functions and some simple isset logic for review.php, do you suggest putting those directly into review.php?

Generally speaking functions should be kept out of the HTML certainly, infact as much PHP as possible should be kept seperate, but I don't see how the approach changes. You could place it in review.php at the top of the page. If you really wanted to keep it seperate but it in a seperate functions script and simply include the functions script on any pages that require. If the page is specific to a single page though, theres obviously no point it being in a seperate script.

There is no real right way, it's all down to personal preference. I must admit I found getting to grips with the best structure for a site far more difficult than I found getting used to PHP syntax. Generally speaking my structure is like so...

 

<?php
//- FILE START
$title = "Title for page";
$keywords = "keywords for page";
$description = "descrip for page";
...
// etc

include 'header.php';

// main markup of page

include 'footer.php';

//- FILE END
?>

 

header.php will have includes for settings, mysql_ connections etc, it will also contain the HTML declaration, <head> section and begining of the <body> section. It will also generally include a header image and a site menu.

 

footer.php will contain the actual site footer, close any mysql_ connections, do any other tidying up and close the </body> tag.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.