Site project, individual files or collected
Moderator: General Moderators
Site project, individual files or collected
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.
So now i want to know which system you think is the best.
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
also, if you could tell me some pros and cons when using either method, i would be grateful
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.
/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.
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. 
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?
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?
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
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! ]
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.
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?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.
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
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.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...
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
.
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
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
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
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
