Site project, individual files or collected

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Site project, individual files or collected

Post by vigge89 »

I'm right now about to start working on my new site, however, i'm not sure which "file"-way i should go with. Having one file for each page which then have a global function which outputs the output, or having one index-file which loads the requested page, formats it, and finally outputs it.

So now i want to know which system you think is the best.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

what i mean is that using either one external file for each page which just loads some major configurations (links.php, downloads.php etc.), or having one file which loads the requested page (trough index.php?admin), and then displays it.

also, if you could tell me some pros and cons when using either method, i would be grateful :D
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

I tend to use the directory structure as the 'navigation', eg
/account/
/admin/
/uploads/
etc.. and keep to individual files. /account/login.php /account/logout.php etc..etc..

Then i use an auto_prepend_file to put any config stuff, defines, requires/includes etc etc..
I'm not a huge fan of the 'one file handles all' thing (index.php?page=admin) as i usually end up with so many unique cases that this file becomes ugly after a while.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Having one global.php file is probably the best way to go. And each file (search.php, this.php, that.php) can have a function from the global.php that will output what is needed. So all you really need to edit (when needed) is the global file, without having to open up 5-6 files at a time like I used to do. :?
Image Image
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

what I did with @keeper (http://www.vigge.net), is having one global file which contains database connection, some general stuff and the output()-function which when used outputs the page. Then i had one file for each page (like phice said).

However, the new project i'm about to start is going to have "dynamic" page-content, becuase the content (which is BBCode formatted) of the page is going to be editable. Should i use MySQL or flat-files for storing it? MySQL is good, but flat-files would be better if I need to download/transfer the content (faster). Also, I don't want to include a big block of code in each file which loads the content, so having a function which does it in the global file looks good to me, but what do you think?
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Sounds like your trying to decide between a front controller or intercepting filter. I use to use a front controller structure where everything went through index.php. However, I found using intercepting filters much more flexible.

The intercepting filter structure offers a number of advantages:
Pages have there own filenames and this make caching static content much easier. Since pages now have filenames once again I find it much easier to organize a project. Every page can process user input, but you can also organize commands by filenames. I find that really helpful. I would like to see more projects use the intercepting filter pattern just to see what other come up with. :)

[Edit - Hey! It's my first post here! ]
Last edited by Buddha443556 on Fri Mar 19, 2004 1:56 pm, edited 1 time in total.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Buddha443556 wrote:Sounds like your trying to decide between a front controller or intercepting filter. I use to use a front controller structure where everything went through index.php. However, I found using intercepting filters much more flexible.

The intercepting filter structure offers a number of advantages:
Pages have there own filenames and this make caching static content much easier. Since pages now have filenames once again I find it much easier to organize a project. Every page can process user input, but you can also organize commands by filenames. I find that really helpful. I would like to see more projects use the intercepting filter pattern just to see what other come up with. :)
that's exactly what i think, easier to manage forms, and also much simplier to handle everything at all. But which type of database do you think I should use, MySQL or flat-files?
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

vigge89 wrote:that's exactly what i think, easier to manage forms, and also much simplier to handle everything at all. But which type of database do you think I should use, MySQL or flat-files?
The only reason to use Flat-files is if you don't have MySQL access.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

yay! :?
i think i'll go for it then... :wink:
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

well, i went with onefile-acees-all, becuase of the contents of the pages are loaded trough a database, so more than one file was unneeded...
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

vigge89 wrote:well, i went with onefile-acees-all, becuase of the contents of the pages are loaded trough a database, so more than one file was unneeded...
Darn another front controller created. Oh well... I really can't think of one example of an intercepting filter CMS in PHP, can you? I'm working on one and I sure wouldn't go back to using a front controller it just seems so limiting now. Maybe after I get all my dynamic routines converted to the intercepting filter structure I'll release a basic framework. :wink:
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

well, what i did with @keeper was kinda bad;
i loaded a global file in each page (file), whioh contained some basic thingd like session_start, db-connect, etc.., and also a output()-function which outputs the given output (called by output ("text, html, everything")). When output was called, it included output.php which outputs the whole bunch of code, and then kills PHP.

I was a bigger newbie when i started with @keeper, so that's why all the code looked so bad, and also why the system sucks :? :wink: .

the project im coding right now (mgs3-core), is based on what I think you call a front controller, one file which loads the content for each page, and then outputs it. However, since i need to be able to edit the pages, i edited the front controller a little so if i set $output['text'], $output['title'], etc. before i includes the file, it shows that content instead, if you know what i mean. So you could say that the front controller works as a template-file.

For the first time ever, i've been able to code an OK system for outputting content :D
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

For the first time ever, i've been able to code an OK system for outputting content.
Cool!
Post Reply