Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm a web development intern working on a small PHP application (just a few pages with a little database access) which has fast become a couple of very non-DRY, non-OO, individual scripts.

A framework seems like overkill (maybe not?) but I was wondering what some best practices for code / folder structure and general solo, small-scale PHP development. What is your starting point for a small application such as this?

share|improve this question
    
you should use a MVC framework. –  pandu Aug 1 '12 at 14:24
2  
MVC framework will be an overkill for simple php application. –  Yusubov Aug 1 '12 at 14:38
2  
IMO, the only truly correct answer "just don't do it." While it's possible to work around PHP's lousy design to produce things that work (yes, quite well in a few cases) it's roughly equivalent to pushing an egg with your nose to get it from one place to another -- cute as a party game, but completely insane as a method of transportation. –  Jerry Coffin Aug 1 '12 at 14:57
2  
Framework...probably not. Live the mantra, first get it working, then make it beautiful. Just don't let them know it works yet or the ugly will be what you are stuck with ;) –  Rig Aug 1 '12 at 15:27
add comment

4 Answers

up vote 1 down vote accepted

The thing about "small" projects is they rarely stay small. If they're successful they grow. Otherwise they die. What happens is you add "just one more little thing" until eventually you have implemented a framework anyway, and it's usually poorly designed because it was never intended to grow.

Even if you are convinced this time is different and your application won't grow, there are so many things you get for free with a framework that I have a hard time seeing why anyone would forgo it. You get themes, user authentication and roles, administration pages, tested modules, security fixes, and more, all of better quality than an individual developer starting from scratch could produce.

Yes, there's a learning curve associated with any framework, which is why people think they're saving time by starting from scratch. That notion is very short-sighted. It's ridiculous to assume that learning a heavily used and tested software application is harder than implementing one of your own from scratch. They have already encountered and solved hundreds of problems that you aren't even yet aware exist.

share|improve this answer
add comment

Did you try using thinga like Silex, micro-framework from Sensio Labs?

There are number of other practices on code organization, and framework usage that you may find helpful:

share|improve this answer
add comment

Well my advice for you is to use MVC and a PHP framework.

This will let you focus more on developing the application itself rather than the basic setting up of the project structure.

I use Zend framework and it's great. The only drawback is its steep learning curve and awkward documentation. However, it has the biggest library of classes I have ever seen.

If you feel intimidated by the complexity of Zend framework then you can try CodeIgniter which has the best documentation out there in addition to many video tutorials. These tutorials got me to understand MVC in action.

When you get comfortable with it maybe you can move to a more full stack framework such as Symfony or CakePHP.

Note:

Some will argue that frameworks such as Zend, Symfony and CakePHP are overkill for a simple application, but it all depends on goal. If you just wanna build the application fast and dirty make some scripts and it will work fine.

However, if you really want to learn good OO design practices and deep knowledge from some of the top frameworks out there the go for the kill :)

share|improve this answer
add comment

For small scale PHP development you can use MVC framework. It will allow you to have your codes and folders organized. One of which is CodeIgniter. They have good manual which is also included when you download their framework and they have a much bigger community.

But if you want to make your own framework you can try this folder structure.

lib/ == contains your classes
app/
app/view == contains the templates
app/model == contains the business logics
app/controler/ == contains the implementations of the business logics
config/ == site configurations
index.php
.htaccess
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.