So I'd like a few opinions on this as Im new to php and wondering which is the best way to go.....
Should i make a site or say a section of a site in one file and then use the get url to display different sections of that file
i.e
url = example.com?location=about
if ($_GET = 'about') display this
or should i put these "seperate sections" into different pages and reference them? i.e about.php, work.php, etc.....
What do you think are the advantages/disadavantages of the two above methods and do you have any other/better methods?
thanks
site in 1 file displaying using get or in 5 different files?
Moderator: General Moderators
-
bennyChidge
- Forum Newbie
- Posts: 17
- Joined: Fri Sep 19, 2008 4:40 pm
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: site in 1 file displaying using get or in 5 different files?
If your new to PHP this is the best way until you get to realize the disadvantages and work towards using a single index.phpor should i put these "seperate sections" into different pages and reference them? i.e about.php, work.php, etc.....
Try it and you shall see.What do you think are the advantages/disadavantages of the two above methods and do you have any other/better methods?
centralizing everything through a single point of entry will make life easier but don't take my word for it.
-
bennyChidge
- Forum Newbie
- Posts: 17
- Joined: Fri Sep 19, 2008 4:40 pm
Re: site in 1 file displaying using get or in 5 different files?
I can see that one file means its much more manageable to work with rather than lots of files, my concern is making that one file say 200k! and the effect that would have in comparasion to seperate files for being rendred and managed on the server. Is one better than the other?
Whats the best practise?
Whats the best practise?
Re: site in 1 file displaying using get or in 5 different files?
If you have a single file with different cases for your "pages", then only the code for the case specified by the GET variable will be executed by the server. All other cases will be false and get skipped over. The result is that 200k of code will execute in a few milliseconds or less on the server end, and only a few kb of content will actually be downloaded by the client.
The concern I have encountered with having a single file is that one bug in your code could practically takes down the entire site, since the entire site is inside the one file with the bug. You face risk of broader failure by putting all your eggs in one basket. I personally create different pages for each module of the site, and have all the functions of each module encased in one page. So for example, I have a user.php page that has cases for login, create new account, manage profile, reset password, etc. If I need to edit the login code, there is 0% chance of negatively affecting any other parts of my site but the user code.
This is a similar concept to why developers manage site format in a stylesheet, as opposed to defining styles within the code. Any time you make changes to your code you risk adding a bug.
Sorry if that was long winded. The conclusion really is just that either way is acceptable, but it boils down to factors of site content, code complexity, and personal preference of how you want to manage it all.
The concern I have encountered with having a single file is that one bug in your code could practically takes down the entire site, since the entire site is inside the one file with the bug. You face risk of broader failure by putting all your eggs in one basket. I personally create different pages for each module of the site, and have all the functions of each module encased in one page. So for example, I have a user.php page that has cases for login, create new account, manage profile, reset password, etc. If I need to edit the login code, there is 0% chance of negatively affecting any other parts of my site but the user code.
This is a similar concept to why developers manage site format in a stylesheet, as opposed to defining styles within the code. Any time you make changes to your code you risk adding a bug.
Sorry if that was long winded. The conclusion really is just that either way is acceptable, but it boils down to factors of site content, code complexity, and personal preference of how you want to manage it all.
-
bennyChidge
- Forum Newbie
- Posts: 17
- Joined: Fri Sep 19, 2008 4:40 pm
Re: site in 1 file displaying using get or in 5 different files?
never to long winded.
I have come to many of your conclusions to. I dont see bug's as a problem as I am testing massively (ex QA man) on my localhost before I go live. I can see the benifits of having everything in one place, I was concerned on file size.
I also will be having sections of the site in different files, for instance the cms, the front end, the shop etc. I am a big fan of seperating eveything (css and js from my xhtml particularly) so this seems like a logical step to also take.
I have decided to go with a solution offered by another forum, similar to yours but with includes creating one huge page and then spliting them into various include files - this works for me.
Thanks as always for the comments
I have come to many of your conclusions to. I dont see bug's as a problem as I am testing massively (ex QA man) on my localhost before I go live. I can see the benifits of having everything in one place, I was concerned on file size.
I also will be having sections of the site in different files, for instance the cms, the front end, the shop etc. I am a big fan of seperating eveything (css and js from my xhtml particularly) so this seems like a logical step to also take.
I have decided to go with a solution offered by another forum, similar to yours but with includes creating one huge page and then spliting them into various include files - this works for me.
Code: Select all
http://www.example.com?location=home
$page = $_GET('location');
include($page . '.inc.php');
Re: site in 1 file displaying using get or in 5 different files?
That is an excellent implementation that sort of meets in the middle between the two extremes. I forgot about that method, and I actually employ it on one of my pages. My shopping cart checkout has complex code for each step, so I have the code for each checkout step in a file of it's own. It doesn't make sense to have the client access multiple pages just for checkout, but it's not logical to write all of the complex code such as Paypal IPN or API functions into a single large page with other complex code.
To elaborate on my point about bugs though. I too have some support and QA experience on my resume, but I've learned even the most complex test cases can't cover every scenario to shake out bugs. A majority of these occurrences usually deal with applications that take in user input, so it may or may not apply to your site. It's so frustrating when I approve some code for live, just to hear a user say "I get an error when I try to use an apostrophe" or some stupid obscure scenario like that. So even in cases like my own site where I develop and manage everything myself, I will once in a while come across some silly bug I never planned for. I never rule out the chance that the unexpected may occur, and I code with this in mind.
To elaborate on my point about bugs though. I too have some support and QA experience on my resume, but I've learned even the most complex test cases can't cover every scenario to shake out bugs. A majority of these occurrences usually deal with applications that take in user input, so it may or may not apply to your site. It's so frustrating when I approve some code for live, just to hear a user say "I get an error when I try to use an apostrophe" or some stupid obscure scenario like that. So even in cases like my own site where I develop and manage everything myself, I will once in a while come across some silly bug I never planned for. I never rule out the chance that the unexpected may occur, and I code with this in mind.
-
bennyChidge
- Forum Newbie
- Posts: 17
- Joined: Fri Sep 19, 2008 4:40 pm
Re: site in 1 file displaying using get or in 5 different files?
all great pointers ill keep in mind and use your advise as bugs arnt known about until they are discovered
heres the link on another forum for the suggestion from the same question from someone else (i dont want to take credit where credit is not due)
http://www.webdeveloper.com/forum/showt ... post942775
heres the link on another forum for the suggestion from the same question from someone else (i dont want to take credit where credit is not due)
http://www.webdeveloper.com/forum/showt ... post942775