Page 2 of 6

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

Posted: Fri Feb 06, 2009 11:49 am
by josh
Yeah I agree I dont know anyone quite like Jab, lol. Normally the file version thing is when another company is depending on your code. Maybe Google has an API into your site and if you told us you'd have to kill us? 8O

I certainly dont keep all the code in index.php, that would be really unreadable. I actually saw some photo gallery that did that the other day, turned down the project of course. Index.php is my main entry point of course and everything else is a class. I use Zend Framework as well.

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

Posted: Fri Feb 06, 2009 12:28 pm
by John Cartwright
Jab, your file structure makes me nauseous.

//bows out of thread

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

Posted: Fri Feb 06, 2009 1:37 pm
by Eran
Josh, what IDE is that? looks decent

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

Posted: Fri Feb 06, 2009 2:31 pm
by josh
phpED

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

Posted: Fri Feb 06, 2009 4:21 pm
by JAB Creations
PCSpectra, Version 2.9 is about getting rid of third party modules so I don't have to completely redo templates for every single update they come out with (I have yet to find a decent template and decent default XHTML code). Version 3.0 will enhance 2.9 but you have to clear land before you use it to farm so to speak.

I don't see what the fuss is about my file system (in the terms I'm using it Josh)? I don't understand keeping a single PHP setup in multiple folders. I of course have separate folders for JavaScript, images, etc but why keep changing folders when I can have all the files I need to access in a single location?

Actually Google's code is a bit noxious to me. It's bulky, framework dependent, non-standards compliant...I mean it's just the complete opposite of what I like and do.

Are most of you generating header and footer XHTML directly from your databases? I don't see any files that suggest handling things like a sidebar or menus and other clientside bits?

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

Posted: Fri Feb 06, 2009 7:30 pm
by Chris Corbyn
JAB Creations wrote:Are most of you generating header and footer XHTML directly from your databases? I don't see any files that suggest handling things like a sidebar or menus and other clientside bits?
You've been a member here since 2005. Maybe now's time to see how other people develop applications in tried, tested and almost standardized ways. Starting with MVC perhaps? ;)

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

Posted: Fri Feb 06, 2009 7:42 pm
by Eran
I don't understand keeping a single PHP setup in multiple folders. I of course have separate folders for JavaScript, images, etc but why keep changing folders when I can have all the files I need to access in a single location?
Think for a minute about your hard drive setup. There is a reason you don't have all files in the root directory - it gets messy.

Real web projects can quickly grow to dozens and even hundreds of scripts (not including external libraries). Creating an easy to follow directory structure is a must for keeping projects maintainable.

Personally I use the PEAR/ZF directory structure, with MVC components in their respective directories and the rest follow the the PEAR naming convention in which a class name represents the directory it is in using underscores to represent directory separators. Those are not only easy to follow conventions, they are also as close to a standard as there is in PHP development, which is important if you value those things (coding standards). I obviously do.

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

Posted: Fri Feb 06, 2009 8:07 pm
by josh
JAB Creations wrote:Are most of you generating header and footer XHTML directly from your databases? I don't see any files that suggest handling things like a sidebar or menus and other clientside bits?
View scripts are in the views/ directory. Layouts in the layouts/ folder

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

Posted: Fri Feb 06, 2009 9:31 pm
by Bill H
The fact that you created the method and that it is unique to you does not necessarily mean that it is the best way to do it, or even that it is the best way for you to do it.

Practices that are "standard practice" are "standard practice" because a lot of people have tried them and found that they work well, and have tried other ways and found that they don't work as well as "standard practice" does.

People who use "standard practice" are not dumber than people who don't, and people who eschew "standard practice" are not smarter than people who follow them.

We had a landscaper working for our HOA who had his own way of doing things, who eschewed "standard landscaping practices" in many ways. He considered himself too smart to do things the way all the other landscapers did, and had his own unique way of doing everything. We fired him when all of our plants started dying.

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

Posted: Fri Feb 06, 2009 11:31 pm
by josh
Seconded. It's like you represent hierarchy by performing modified preorder traversal. That's what directories are for. Like serious, UI design or usability has nothing to do with # of clicks so the argument "files are all right there" is moot, I'm guessing it works for you because you have so few files and each file has a lot of code in it. Rather than worrying about how "far away" files are, it would be wise to structure the code inside of those files, first. I still don't get what's wrong with folders / directories :D

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

Posted: Fri Feb 06, 2009 11:57 pm
by JAB Creations
Well I do use folders for things that aren't directly content related...

admin/
error/
images/
scripts/
themes/
themes/classic/

My collection of PHP functions isn't as extensive as my JavaScript functions.

What benefit would I gain by implementing an MVC? The last thing I want to do is become dependent on any IDE or framework as it would defeat the point of my learning everything to understand it better. I'm not saying I'm in any way above improving myself and my code, I just have to be able to clearly see the logic behind it. I have considered a themes/functions directory though like I said I don't have that many functions at the moment.

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

Posted: Sat Feb 07, 2009 12:09 am
by josh
Well for one, you could re-use business logic with multiple views. You could re-use presentation logic thru view partials ( widgetized content ). You could re-use validation / user flow thru controller inheritance. You can use the principles of OOP properly, if you use a framework like Zend w/ it's view helpers you could stop writing monotonous repetitive form codes. If you don't want dependencies you can write your own but I wouldn't recommend that, at least not until you understand why you would write a framework, which requires using one for probably a couple months. the M in MVC just stands for model, you want as much of your code as possible in the model ( with the exception of anything specific to a presentation, which would go in a view "V" ). Instead of creating /user/account/logout.php for example ( a PHP script for each "command" ) you have "C" ( controller ) which are better ways to group things, instead of a directory of PHP files ( page controllers ) you have 1 "object controller" that has a method for each action.

If you used MVC you wouln't have to worry about creating header.php and footer.php either since that would be handled thru a layout. Once you get the hang of layouts you'll create way more partials then the proverbial, dull "header", "footer", "content". You'll start defining layout variables like sidebar, nav, etc... You'll save yourself countless includes() and require() polluting you code. You'll never have to deal with a 5,000 line file again. Of course maybe you'd rather have your code coupled to a paradigm that is 30 years old then a framework that the majority of the enterprise community is now using

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

Posted: Sat Feb 07, 2009 12:39 am
by Chris Corbyn
You don't need a framework to implement MVC... you can do this yourself which is what I was suggesting you do. It's about separating your concerns, it's not specific to a framework.

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

Posted: Sat Feb 07, 2009 1:22 am
by JAB Creations
Chris, yeah I have been reading about PHP and MVC's such as on devshed and other sites. It seems like it may be another evolutionary step for me.

Josh, here's the thing...I'm dense. I won't be shy about admitting it, I've unfortunately driven Vladsun crazy in plenty of threads because he's great with concepts while they fly over my head. Give me a practical example of applying a concept in minimal application with a why this and why not that explanation and I'll catch on. Like when you guys explained relational databases I really couldn't see the point however I realized that by using an ID instead of a static name the name itself became dynamic...like having the name being a static HTML attribute being converted in to a CSS class (<element width="100" to <element class="width_100" in example analogy). I sort of understand what you're saying though having a very minimal working example with a practical application in use would help me catch on the fastest. By the way the largest files in my themes directory are barely over 4KB in size.

Conceptually a linear example would help...and let's say we need to determine if the page requested should display a sidebar or not? Would that be a good and minimal example to work with though eventually build upon?

If so here is a simple XHTML page I could start with...

Code: Select all

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>Example</title><base href="http://localhost/" /></head> <body> <div id="content">content</div><div id="sidebar">sidebar</div> </body></html>
I need classes obviously though I'm not sure about the minimal number of classes. Is the sidebar XHTML code stored in it's own class, function, etc? If we want the sidebar let's just say we echo it, otherwise we don't. So I presume if we do what are we calling to make the sidebar part of the XHTML output?

If this isn't an effective example I'm open to other suggestions.

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

Posted: Sat Feb 07, 2009 1:53 am
by josh
JAB Creations wrote:Josh, here's the thing...I'm dense. I won't be shy about admitting it, I've unfortunately driven Vladsun crazy in plenty of threads because he's great with concepts while they fly over my head. Give me a practical example of applying a concept in minimal application with a why this and why not that explanation and I'll catch on.
I was the same way for at least a year or 2, I kept hearing MVC MVC and I was like wtf? lol... I agree you will understand after you view examples.

Check out these videos
http://framework.zend.com/docs/screencasts ( skip the 1st unless you dont know to unzip a file hah )

I recommend following thru and creating the code, its virtually impossible to just think about this stuff and understand it fully. SUre you can look at it and tell what the code does but you need to go thru the physical experience of creating the code not the mental experience of considering it, if that makes sense.
http://framework.zend.com/docs/quickstart

As far as implementing your own MVC its definitely doable, but itd be like trying to learn about polymorphism by writing an object compiler. Definitely doable but IMO not the way to learn.

http://framework.zend.com/manual/en/zen ... asics.html