|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
jigga jigga what?
![]() ![]() ![]() Join Date: Oct 2002
Location: Utah (USA)
Posts: 309
|
How much INCLUDE is too much?
I'm building a CMS and am entertaining thoughts of making it entirely an index.php thing, with every function of the site being written into a PHP function and stored in a series of external *.inc.php files. Everything would redirect back to index.php and a session variable could be used to determine what function the user wants to perform.
I can see this will require a lot of IF statements, but I think that may be better than a lot of files with duplicated information in them. Also layout and design will be a bit easier with index.php being the only front-line file. I expect this system to stay relatively small, but am wondering the implications of using this idea even for medium to large scale PHP solutions. Any thoughts?
__________________
$slider = 'n00b'; |
|
|
|
|
|
#2 |
|
killall -9 lusers
![]() ![]() ![]() Join Date: Oct 2002
Location: Cincinnati, Ohio, USA
Posts: 395
|
From a technical standpoint, what your describing should work. However, I personally don't like that kind of layout. It makes the code harder to work on, and it adds unnecessary overhead to the system.
If your main concern is not wanting to duplicate information/functionality across different pages, just create include files with related functions/classes and include these in each of your pages. For instance, most applications that I create have an 'app_init.php' and an 'app_exit.php' file that is included at the beginning and end of each page respectively. 'app_init.php' takes care of things like starting a session, turning on output buffering, creating a template object, including class files that are frequently used, etc., and 'app_exit.php' takes care of cleanup tasks such as flushing the buffer, error reporting, etc.
__________________
Regards, John Wilger ThatWebThing - Design, Usability and Programming for the Web |
|
|
|
|
|
#3 |
|
SitePoint Addict
![]() ![]() ![]() Join Date: Sep 2002
Location: Sweden
Posts: 251
|
ok i think i made a misstake here...
i'm not sure if i understand yall but chanses are that i have been doing things like slider here was thinking... i would like to hear more about diffrerent ways to navigate and include, remove, replace header, body etc.. etc... although.. i could be way of here.. noob ![]() anyway.. here is how my current project looks like.. index.php PHP Code:
1 default body 1 simple page with text 1 submission form containing 2 files that needs to be included... oh i dont wanna anoy you with this.. would just like to know of other way to do this... thanx //noise |
|
|
|
|
|
#4 |
|
SitePoint Zealot
![]() ![]() Join Date: May 2001
Location: Virginia
Posts: 126
|
noise, that is *sort of* what I was doing with EQGMS
Although, what I did was make a page for each section (news.php, admin.php, events.php, etc). The index file would always handle the request, and parse the query string, and example of which would look something like this: index.php?section=news&op=post_news index.php would then look at the section argument and call the appropriate file (news.php in this case). in news.php there is an include that calls api/news.api.php while houses all the news-related functions. news.php then parses the "op" argument (through a rather lengthy case statement, similar to what you listed) and call the appropriate function. the entire process looked similar to this (some code snippets from EQGMS) index.php PHP Code:
PHP Code:
![]() Slider, Using an include system is very viable, especially for a smaller system. For a larger system, I don't see *too* much overhead occuring if you use case statments. A large if/else if block might not be too bad either. I have recently been experimenting with including the function name in the query string. something like: index.php?class=News&method=PostComment&id=10 I have successfully been able to call, for example, the $$_GET['class']News->$$_GET['method']() method, but it gets kind of fuzzy when trying to access arguments, which will probably have to be ripped from the query string. I don't remember the exact syntax I used, but it was similar to the above. this totally eliminates if/else/if blocks, as well as case statements -- possibly allowing your application/cms to scale quite a bit higher. I don't have any examples of this here at work, but if you would like one, just say so and I will post what I have at home (when I get ther) ![]() |
|
|
|
|
|
#5 |
|
jigga jigga what?
![]() ![]() ![]() Join Date: Oct 2002
Location: Utah (USA)
Posts: 309
|
What a trip. Alarion, your EQGMS is exactly what I'm building. Though I'm still in the preliminary stages of it, lots of planning still to do even. I even envisioned/planned v2.0 with full phpBB integration. How long have you been working on EQGMS? How many hours would you say you've put into it already? Is it just you working on it alone?
The reason I'm thinking of doing it all through includes is cause the layout is all the same. I'm going to have a little box in the upper left corner that will either display login fields (if you're not authenticated) or a welcome message (if you're authenticated). I'm going to have a top navigation area with links to the overall site areas, and a left navigation area with links to the separate functions within each major site area. I see no reason to make separate files to do all this, as the header, nav panels, login/authentication box will all be in includes, and then the main page area (think frames here, but done without frames) will just be variable based on whatever the user is wanting to do/see. If a single session variable is used to track what "function" the user is wanting to perform the main page area could simply be an include for that specific function. While I was just gone to class after I posted this thread I even thought of a way to do this without having to use any IF or case statements. And if you look at it right, it is exactly the opposite (if that's the right word...) method from using separate front-end files. I'll be using separate back-end (include) files. Each one of the include files will simply be named appropriately so that as a user navigates around the site, the session variable can be used inline to include the appropriate back-end file. The user wants to see the news? $_SESSION['action'] = "news"; redirect to self... top of index main include is simply include ($_SESSION['action'].inc.php); Other includes will be standard, layout will be standard, no need to have separate front-end files. index.php covers all the bases. I think using the above it's even scalable to a large degree, though that would need to be tested. Further thoughts?
__________________
$slider = 'n00b'; |
|
|
|
|
|
#6 |
|
SitePoint Zealot
![]() ![]() Join Date: May 2001
Location: Virginia
Posts: 126
|
that's also a good idea, actually. That's sort of the way my database abstraction library works (actually, most PHP DB Abstraction libraries work like this).
the main included file includes the appropriate "driver" file and calls functions which are redefined in each include file. Applying this to a CMS, your presentation layer would be your drivers, but they would be things like "news" or "forums" etc... as for EQGMS.. I mainly worked on it at work when things were slow (shhh, don't tell my boss) I would say it took... less than 60 man hours. that includes database design, template input, etc. while that might sound like a lot, there were a lot of things I had to figure out (mainly algorithms).. like nested comments and a halfway efficient way to display and navigate them (nested, slashdot-style comment system)I think I started the project a little over a year ago |
|
|
|
|
|
#7 |
|
jigga jigga what?
![]() ![]() ![]() Join Date: Oct 2002
Location: Utah (USA)
Posts: 309
|
I downloaded your files from sourceforge, but haven't looked at them yet. What state is your project in at present?
__________________
$slider = 'n00b'; |
|
|
|
|
|
#8 |
|
killall -9 lusers
![]() ![]() ![]() Join Date: Oct 2002
Location: Cincinnati, Ohio, USA
Posts: 395
|
What I'm curious about is the actual benefit you are realizing by having everything be parsed through 'index.php' as opposed to having a real URI for the information someone is trying to get to and simply including a header and footer file in that page which holds the global functionality that needs to be present.
__________________
Regards, John Wilger ThatWebThing - Design, Usability and Programming for the Web |
|
|
|
|
|
#9 | |
|
jigga jigga what?
![]() ![]() ![]() Join Date: Oct 2002
Location: Utah (USA)
Posts: 309
|
Quote:
I had a nice epiphany earlier, but you know how epiphanies can go... wasn't all that practical once I really worked out all the details.
__________________
$slider = 'n00b'; |
|
|
|
|
|
|
#10 | ||
|
SitePoint Addict
![]() ![]() ![]() Join Date: Sep 2002
Location: Sweden
Posts: 251
|
lol
Quote:
here is what i'm doing on a another site: let's say that site has 9 different MAIN MENU links (9 different main sections of the site, like "lyrics, contact, links, etc) here is a snippet of MAIN menu: PHP Code:
like... lyrics -> (def.php search_db.php, submit_lyrics,.. etc) here is SUBmenu of lyrics section: PHP Code:
all includes are handled here... PHP Code:
One more thing... i noticed that every path i put in (image, dir, etc) anywhere in any dir/file.. path is always starting from the dir that test_main.php is in (INDEX.php). but i want to know more about what KillAllDash9 said earlier: Quote:
sounds lill simpler.. but i did'nt understand quite well*all this prolly looks like a n00b's way of doing things.. but that's just what i am.. //noise Last edited by noise; Oct 29, 2002 at 23:16.. |
||
|
|
|
|
|
#11 | |
|
killall -9 lusers
![]() ![]() ![]() Join Date: Oct 2002
Location: Cincinnati, Ohio, USA
Posts: 395
|
Quote:
This site would have the following areas: Homepage - lists the last diary post and displays thumbnails of five most-recently added pictures. Date Index - lists diary entries and photos by date, shows date and title for x entries at a time with previous/next buttons. Topical Index - lists topics that diary entries and photos appear under, clicking a topic takes you to a list of entries for that topic. Diary Entry - displays a single diary entry. Photo - displays a single photo with caption. Admin section - it would have to be there, but I won't describe it here for the sake of brevity. Let's also say that you require visitors to login to the site before they can read entries or view photos (wouldn't want your boss to know what you really think of him now, would you?) There is certain functionality that should be present in every single page. You will need to start a session to keep track of the logged-in user, you will need to access the database on each page, and you want to use output buffering on each page. You might write a script called 'app_init.php' with the following: PHP Code:
PHP Code:
PHP Code:
Note: the database connection (DBConnection), database query (DBQuery), and Template classes are examples only. Don't get to bent on figuring out that syntax if you don't get it right away. :-)
__________________
Regards, John Wilger ThatWebThing - Design, Usability and Programming for the Web |
|
|
|
|
|
|
#12 |
|
jigga jigga what?
![]() ![]() ![]() Join Date: Oct 2002
Location: Utah (USA)
Posts: 309
|
The thing that's sticking the index.php idea in my head is the great way that frames worked (we all know frames suck, but that's for reasons other than their great way of presenting your site). I guess I've been trying to design a frames-based site without frames. Everything (nearly) in my site is going to be the same except for the main display area, so why not have it be the same front-line file, and that file simply calls appropriate functions through includes for what it needs to display in the main display area? That's my thinking. I don't think it will work too well, so I'm rethinking the entire design (not that I have much yet to have to rework).
What I'm getting interested in now, especially after reading your above post kill, is object stuffs, and templating. I don't know jack about either. Where can I go to learn that stuff? How much do you think it applies to what we've been talking about? Thanks.
__________________
$slider = 'n00b'; |
|
|
|
|
|
#13 | |
|
killall -9 lusers
![]() ![]() ![]() Join Date: Oct 2002
Location: Cincinnati, Ohio, USA
Posts: 395
|
Quote:
For instance, in the 'index.php' example I gave above, there is the following command (more or less): PHP Code:
PHP Code:
However, the object itself doesn't know how to display the data to the user. I use a template object to take care of this, because the goal is to seperate the data form the presentation. So our template file, 'diary_entry.html', might look like this: PHP Code:
Basicly, code it once, use it wherever.
__________________
Regards, John Wilger ThatWebThing - Design, Usability and Programming for the Web |
|
|
|
|
|
|
#14 |
|
SitePoint Addict
![]() ![]() ![]() Join Date: Sep 2002
Location: Sweden
Posts: 251
|
i definitly think that i need to learn some more before i get my hands on OO
![]() gonna go trough this book first and then give it a try... when you say, "code it once use it whenever", i'm thinking well i prolly could manage to get trough it and finnaly produce the code. but then what? i'm in the learning process and "code it once" would'nt give me much i think... specially when i realise that i have no basic ground to stand on. thanx for the advice.. gona print it out and save it for later reading ![]() //noise |
|
|
|
|
|
#15 |
|
killall -9 lusers
![]() ![]() ![]() Join Date: Oct 2002
Location: Cincinnati, Ohio, USA
Posts: 395
|
Yeah, you definately need to learn the basics of the language before you can really make the best use of OOP. :-) I remember some scripts I wrote when I was first starting out that were almost 100% procedural code. Looking back, "Ick" is the only thing I can say if I think about all the wasted lines of code and inneficient programming. However, I also know I wouldn't be at the level I am now had I not gone through that stage. And I also know I still have a long way to go, and that in 5 years I'll probably look back on the stuff I'm coding today with that same thought.
__________________
Regards, John Wilger ThatWebThing - Design, Usability and Programming for the Web |
|
|
|
|
|
#16 |
|
SitePoint Zealot
![]() ![]() Join Date: May 2001
Location: Virginia
Posts: 126
|
I think KAD9 summed that up pretty well.
A programmer is always learning new things (techniques and technologies, etc). Every year, one could probably look back at something they coded and think "why the heck did I do THAT?!" ![]() Stick with it though, it will come in time. |
|
|
|
|
|
#17 |
|
SitePoint Addict
![]() ![]() ![]() Join Date: Sep 2002
Location: Sweden
Posts: 251
|
So true! And the same goes for moste of the things in life, a specially if you are dealing with some kind of creation process. "The more you learn the less you know"
![]() |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 21:09.






I would say it took... less than 60 man hours. that includes database design, template input, etc. while that might sound like a lot, there were a lot of things I had to figure out (mainly algorithms).. like nested comments and a halfway efficient way to display and navigate them (nested, slashdot-style comment system)


Linear Mode
