Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I structure my PHP project?

I am about to embark upon yet another large PHP project. This time, I intend to have the project folder be tidy! So I have a few questions concerning keeping my project clean and DRY:

  • How do I differentiate between PHP source files and PHP files that should be accessed by the browser? In other words, how do I make it clear which PHP files gives output and which gives function or class definitions?

  • I am planning on separating my PHP functions into static classes, separated by subject, for instance database::create() or editor::write(). What are your thoughts on this?

  • I am planning on creating a PHP file "core.php" that will be included at the top of EVERY SINGLE PHP file in the project. This file will handle authentication and include base functions. Thoughts?

  • The project will be heavily Ajax based. This begs the question: Should my PHP functions be actual PHP functions, or should they be individual PHP files that takes GET or POST input? My plan is doing both. I create a folder for PHP source files and one for PHP "ajax" files (or something), and have the latter folder populated with files names by the functions they will perform. The PHP file will then simply contain a call to a function and write output for Ajax. Thoughts?

Any other comments or tips before I start this project would be great!


Edit

I may have failed to emphasize just how heavily Ajax based this web application will be. Codeigniter seems like a great tool for creating web pages or simple web applications such as a blog. My application will be a little different. Much like the uTorrent WebUI, my web application will be static on one page, having Ajax performing all the under-the-cover actions. It seems a little awkward to use Codeigniter for such a project.

Is there a different architecture out there created with this kind of application in mind?

like image 694
Hubro Avatar asked Feb 16 '11 03:02

Hubro


1 Answers

Have you considered using a framework such as Codeigniter? Are you familiar with any sort of design patterns, such as MVC? Both of those would help dictate the location of files and separation of logic in your project.

EDIT: Codeigniter uses MVC, which is just a great pattern for web programming. Check out these two videos they have for tutorials. Only about 30 minutes combined, and definitely full of good knowledge, both as a look at the way their framework works, as well as the insight offered by their folder structure.

EDIT2: http://codeigniter.com/tutorials

like image 136
Josh Avatar answered Sep 16 '22 11:09

Josh