View Single Post
Old 04-06-2009, 08:51 AM   #1 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
Jim is on a distinguished road
Default Framework: Do's and Don'ts

Hi PHP-friends!

It's been a while but I entered a new internship so I'm back :P.

Lately everybody is creating his own Framework, no-one builds websites without them. So with our combined experience we should really know how to create a good framework by now.

Just starting of with something that looks like ZF from the start will only give problems in the end. Before you start creating a framework (or any big project) you have to plan things carefully. This was one of my biggest mistakes. I created a framework which works perfectly fine and stabile, but in the end I wanted it to work differently and even nicer.

My framework runs like this:

Client requests url: /news/32-mymessage.html

index:

- Load Core
- Config
- Initialize a MySQL connection via a Factory->Singleton

core:

- Initialize the main template, start a buffer
- Use reflection to search for a "news" module which uses the IModule interface
- Load the main() function from the module via reflection

module:

- Get content - bla bla not interessting
- Get template via the core and print it with the earlier created content

core:

- Close buffer and paste that in the main template
- Dump the result

This gives a quick example of my framework. I think this works fine, but you will see my problem in the next part: file structure

./index.php
./config.php
./modules/
./modules/modulename/
./modules/modulename/index.php
./template/
./template/templatename/
./template/templatename/modulename/
./template/templatename/modulename/index.tpl
./core/
./core/core.php
./core/lib/
./core/lib/libname.lib.php

As you can see the modules and templates are seperate. I wanted this because I wanted to be able to change the complete layout by assigning a different template and not just the base. But it loses the possibility to just add a new block of functionality by just uploading a folder.

--

Basically I made this topic to exchange ideas about good structures frameworks for your website, so we can learn from eachother.
__________________
Nunchaku! Who doesn't like martial arts? =)
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote