Page 1 of 6

How do you organize your back-end file wise?

Posted: Thu Feb 05, 2009 10:35 pm
by JAB Creations
I read Pickle's thread though it was a bit more on classes and functions. I'm curious as how others organize their file structure.

If you're running Windows with DOS access to your web directory (start-->run-->type CMD-->type D: [enter]-->cd my\web\folder[enter]-->right click/mark, select with cursor, [enter], paste) to generate an easy copy and paste list.

In general I use a themes folder (since each theme has it's sub-folder) to cut down on unnecessary public root folders. With XP's Windows Explorer I organize by type and prefer things alphabetical. Also my site has a lot of functionality you can tweak (look at the tabs) otherwise a lot of the _2_ files would be condensed.

I know some people might like to condense lots of code in to very few files though I find that's a bit much for my taste. I've been adapting this to be as modular as I need so for example it's difficult in Version 2.8 to connect to the database without automatically setting the media type/mime where I've taken such things in to consideration. I'm not sure how much if at all I'll condense the files once this has matured.

Here is Version 2.9 Alpha 3's listing...

_0_header_00.php
_0_header_01_functions.php
_0_header_02_mysql.php
_0_header_02_mysql_authentication.php
_0_header_03_classes_01_cms.php
_1_functions_ajax_00.php
_1_functions_ajax_01_chat_01-activity.php
_1_functions_ajax_01_chat_02_list.php
_1_functions_ajax_01_chat_03_messages.php
_1_functions_ajax_01_chat_04_post.php
_1_functions_ajax_01_chat_05_exit.php
_1_functions_ajax_02_poll_01_poll.php
_1_functions_ajax_02_poll_02_results.php
_1_functions_ajax_03_registration.php
_1_functions_bb.php
_1_functions_file_system.php
_1_functions_permissions.php
_2_includes_01_xml.php
_2_includes_02_dtd.php
_2_includes_03_head.php
_2_includes_04_title.php
_2_includes_05_meta_00.php
_2_includes_05_meta_01_description.php
_2_includes_05_meta_02_keywords.php
_2_includes_05_meta_03_language.php
_2_includes_05_meta_04_robots.php
_2_includes_06_base.php
_2_includes_07_css.php
_2_includes_08_js.php
_2_includes_09_body.php
_2_includes_10_overflow.php
_2_includes_11_content_01_permissions_00.php
_2_includes_11_content_01_permissions_01.php
_2_includes_11_content_01_permissions_02.php
_2_includes_11_content_01_permissions_03.php
_2_includes_11_content_02_status.php
_2_includes_12_sidebar-00.php
_2_includes_12_sidebar-02-01.php
_2_includes_12_sidebar-02-02.php
_2_includes_12_sidebar-02-03.php
_2_includes_12_sidebar-03-news-archives.phpp
_2_includes_12_sidebar-03-news.php
_2_includes_12_sidebar-05-poll.php
_2_includes_13_overflow-end.php
_2_includes_14_prompt-00-tab-anchor.php
_2_includes_14_prompt-00.php
_2_includes_14_prompt-01.php
_2_includes_14_prompt-02.php
_2_includes_15_prompt-end.php
_2_includes_16_head.php
_2_includes_17_location.php
_2_includes_18_menu.php
_2_includes_19_head-end.php
_2_includes_20_footer.php
_3_template_01-1.php
_3_template_01-2.php
_3_template_02-redirect-1.php
_3_template_02-redirect-2.php
_3_template_02-redirect-3.php
_4_patch-tab-0.php
_4_patch-tab-1.php
_4_patch-tab-3.php
_4_patch-tab-4.php

In general this keeps me very well organized and I can easily adapt new files where I need. I'd like to see how others handle PHP and their file system in general, maybe share some nifty tips. :)

Re: How do you organize your back-end file wise?

Posted: Thu Feb 05, 2009 11:44 pm
by josh
This post makes no sense to me

Re: How do you organize your back-end file wise?

Posted: Thu Feb 05, 2009 11:52 pm
by JAB Creations
Josh, do you put all your site's code in to index.php then?

Re: How do you organize your back-end file wise?

Posted: Thu Feb 05, 2009 11:55 pm
by Chris Corbyn
I'm a little confused too.

I lay out my code using something like Zend Framework suggests:

/htdocs
/htdocs/index.php
/htdocs/dev.php
/htdocs/css
/htdocs/scripts
/htdocs/images
/config.php
/routemap.php
/bootstrap.php
/application
/application/classes
/application/controllers
/application/templates
/framework

Is your directory structure one-dimensional or is that just MS DOS being weird?

Re: How do you organize your back-end file wise?

Posted: Fri Feb 06, 2009 12:01 am
by JAB Creations
Unless it's an independent PHP script (like my blog or forums) it's stored in the themes directory.

Chris, what do routemap.php and bootstrap.php do?

Re: How do you organize your back-end file wise?

Posted: Fri Feb 06, 2009 12:06 am
by Chris Corbyn
JAB Creations wrote:Unless it's an independent PHP script (like my blog or forums) it's stored in the themes directory.

Chris, what do routemap.php and bootstrap.php do?
What's stored in the themes directory?

routemap.php contains URL <=> Action mappings for my application. bootstrap.php contains all the code that "sets up" the application (such as loading the config and the route map before dispatching the front controller).

Re: How do you organize your back-end file wise?

Posted: Fri Feb 06, 2009 12:20 am
by JAB Creations
All those files are stored in the themes directory. They contain all the code that handles how all the pages on my site are created.

_0_ = headers
_1_ = universal functions
_2_ = XHTML bits
_3_ = template includes (main files include _3_ templates while each of these template files chooses which _2_ XHTML bits should be included)
_4_ = Cloaking patches, currently only needed for Gecko, see Gecko bug 383349 for explanation.

Re: How do you organize your back-end file wise?

Posted: Fri Feb 06, 2009 12:22 am
by alex.barylski
Whats with all the underscores? Are those directory seperators or something?

Re: How do you organize your back-end file wise?

Posted: Fri Feb 06, 2009 12:27 am
by Chris Corbyn
Did I take drugs today? :dubious: Lets see :banghead: Nope, that still hurts :cry:

Re: How do you organize your back-end file wise?

Posted: Fri Feb 06, 2009 12:29 am
by Benjamin
lol 8O

You know, that's cool and all but I don't think it would work for anyone rather than you JAB. Maybe you ought to look into MVC?

Re: How do you organize your back-end file wise?

Posted: Fri Feb 06, 2009 12:33 am
by JAB Creations
No, those are the actual file names. I know exactly what all of those files do. Like I said, modular. :mrgreen: The structure also helps keep the files organized in a sort of linear perspective (vertically speaking top to bottom) of how a page generally executes however I can still include individual files (say if I needed to just include the MySQL connection file just for a small AJAX related PHP script). Again I'll reiterate many of these files wouldn't exist if there wasn't a lot of things you could tweak on my site.

I'm curious if I'm the only Joe on the planet who has thought out a file structure like this?

Re: How do you organize your back-end file wise?

Posted: Fri Feb 06, 2009 12:35 am
by Benjamin
JAB if you spent as much time trying to get rich as you spend on your website, you would be loaded.

Re: How do you organize your back-end file wise?

Posted: Fri Feb 06, 2009 12:43 am
by alex.barylski
The structure also helps keep the files organized in a sort of linear perspective (vertically speaking top to bottom) of how a page generally executes however I can still include individual files
So there all stored in the same directory? You use the underscore as a convention instead direcotries for a linear file (un)structure?
I'm curious if I'm the only Joe on the planet who has thought out a file structure like this?
If I told you no...and then explained it was because experience told me it wasn't a great solution, would you hate me? :P

It is common to use conventions in files to influence the order of each file, etc. Linux does something like this during boot and my own systems use a numeric prefix to order the execution of filters without having to introduce an external file to order filter execution.

For a standard file system layout though...you need to use directories. This layout is not modular it's highly conventional. Modularity is akin to compartmentalization.

Using directories allows a developer quickly and easily swap out entire 'units' of funcitonality by adding/removing a single directory. Using a convetions approach like you have would require me to know exactly which files belonged to which unit of funcitonality, even if convention dictated that 01_xxx.php translated to global functions it's more work than if you had a directory structure like:

Code: Select all

index.php
functions/globals.php
templates/layout.html
Cheers,
Alex

Re: How do you organize your back-end file wise?

Posted: Fri Feb 06, 2009 1:13 am
by JAB Creations
My site is how I learn and frankly as much as I know I'm still learning stuff every day. Most of what I know is clientside and I'm trying to strengthen myself as far as databases go. Last year's new year's resolution was to learn databases, done and then some (relational). This year's new year's resolution is to make money while I sleep. I do have a very viable and attractive business model that I conjured up in my mind a couple months ago and have been working in a sense towards. It's not certainly not what most people would imagine but my goal is to do it all on my own without depending on any business partners, investors, and or third party modules (like frameworks and the like). This year's new year's resolution is to make money while I sleep. Granted I know (or at least only anticipate it to only be) a small initial trickle however as a long term investment by late this year or early next I'll be concentrating on getting more clients for my business model and supporting the model which is dynamic and modular...and how I love those words. Once things are working smoothly I will be concentrating on supporting my business model, my clients, and getting more clients. The startup costs can be covered by the money I make fixing people's computers. While I didn't get the job from the internship this past November I learned that at least for myself and a couple people there don't realize exactly what we can do until we learn enough...but once we learn just you begin to realize all the awesome things you can start doing.

Alex...well I'm really the only person using my own code on my computer and server...or at least I hope so! :lol: I keep adapting the file system as needed and besides a recent post haven't felt any restrictions in what I'm doing. In fact as I'm working on Version 2.9 I keep making notes in my head about what I'm going to do with Version 3.0! But things have to get tested, to go live, etc so I actually limit what I want to do and how much optimization I implement. If I add insane amounts of complexity over what I have been working on then I revise a revision of a revision. So far as compartmentalization I think I have that already (in the sense that I approach it at least) already implemented.

For example my live site has a few general clientside layouts, let's say a gallery page and a general page (with the sidebar). A general file would look like this (Version 2.8 )...

Code: Select all

<?php
include("themes/includes-template_index-1.php");
echo '<title>JAB Creations</title>
<meta name="description" content="Homepage of John A. Bilicki III, a Professional Web Designer and an object oriented PHP Web Developer in Sarasota Florida." />
<meta name="keywords" content="john bilicki,jab,web design" />
<meta name="language" content="en" />' . "\n";
include("themes/includes-template_index-2.php");
include("index.tpl");
include("themes/includes-template_index-3.php");
?>
That's old school though and still doing it the painful way. However 2.9 is database driven...

Code: Select all

<?php
include("../themes/_0_header_00.php");
include("index_functions.php");
include("../themes/_3_template_01-1.php");
include("index_content.php");
include("../themes/_3_template_01-2.php");
?>
...the index_content.php simply contains the $_GET and $_POST arguments (is the page the forum index, a thread, a reply, etc). So any way as far as compartmentalization goes those _3_template files may or may not include _2_includes_12_sidebar-00.php though they would never include any of the finer sidebar include files. Think of it almost as you would with having arrays inside of arrays perhaps.

I don't use any frameworks at all because it forces me to learn how to code it all myself...of course I feel much more solid about saying that in regards to JavaScript then PHP though I think the saying still rings true to a reasonable extent with PHP any way.

I think my approach to things is attributed mostly to the fact that I code solo, no groups, no IM code buddies, no PHP/MySQL programming jobs available in town (except that only one back in November)...and that I get more critique value in general posting then creating a standalone as it's not really viable to put all the code out there like that for my setup...it works for me and it doesn't limit me. Oh and I'm a web designer learning web development so programming doesn't come naturally to me like it may to you guys. I've got everything labeled any way, I've never heard of loading an entire directory to change from one thing to another. Though I almost always implement changes an corrections so even if I approach things differently I try to use good practices in the end. :)

Re: How do you organize your back-end file wise?

Posted: Fri Feb 06, 2009 2:50 am
by alex.barylski
My site is how I learn and frankly as much as I know I'm still learning stuff every day.
We all do...that will never stop until we change careers or disappear :P
This year's new year's resolution is to make money while I sleep. I do have a very viable and attractive business model that I conjured up in my mind a couple months ago and have been working in a sense towards
Money while you sleep sounds fascinating, I'm listening :)
I think my approach to things is attributed mostly to the fact that I code solo, no groups, no IM code buddies, no PHP/MySQL programming jobs available in town (except that only one back in November)...and that I get more critique value in general posting then creating a standalone as it's not really viable to put all the code out there like that for my setup...it works for me and it doesn't limit me
I code solo...most of the time...I have a few friends who are developers but none as crazy about design and best practices as I am so I get my fix by visiting forums like DN, SP, CP, and wherever I can find a disscussion going on about OOD/OOA/etc.

The best experience is had in building full scale applications. I love building CMS, KBase and other expert systems so I am always tinkering. No amount of reading books, articles or job experience can replace that. Developing commercially means you always under the pich of someone else's penny, which means you can never dedicate as much time to the design of the system as you could if it were a personal project. It takes me years to finish projects, even then they are never finished as I always have better ideas for implementing this or removing that.

Refactoring is going to happen, get used to it. The sooner you start, the better off you'll be. Don't put things off until version 3.0 start updating your code ASAP and learn whether it actually works or not. 9 times out of 10 I would say my ideas are flawed in some way and despite having dozens of pages of notes it's the actual implementation of the idea that proves it right or wrong.

Like the old saying goes: You never know unless you try.