New York Design & Development Forums  

Go Back   New York Design & Development Forums > Knowledge Bank > Tutorials
Connect with Facebook

Notices

Reply
 
LinkBack Thread Tools
Old 04-28-2006, 01:54 PM   #1 (permalink)
Administrator
Enthusiast
 
johnboulder's Avatar
 
Join Date: Mar 2003
Posts: 97
johnboulder is just really nicejohnboulder is just really nice
Send a message via MSN to johnboulder Send a message via Yahoo to johnboulder Send a message via Skype™ to johnboulder
Post Application Frameworks - what are they - and do I need one?

Hi all

Just in case any of you are interested, I’ve decided to post something here that might help if you’re considering creating a PHP application framework.

First off – you need to consider if you really need to write one – there are a few out there (such as CakePHP – www.cakephp.com, for instance).

Once you’ve looked through the options out there, and decided (like me) that you really couldn’t be bothered to change your own coding style to fit into someone elses – you then need to draw up a list of requirements for the application handler and the modules within that application.

Why modules, I hear you ask – well, consider this – if you don’t want to decentralize your code, there’s no real point to taking an application/data/interface approach.

This is similar to the MVC pattern on www.phppatterns.org, in that the site is split into 3 sections – the application logic (the controller), the interface (or view), and the data (the model).

First off – define what you want the site to do – this is a crucial step, otherwise you’re going to get bogged down when it comes to the details. Lets take a test scenario:

The project we’ll be discussing here is loosely based on my own current project.

Project definition: A site that will allow developers to share their own code and articles, allow comments on each article, and be easily extensible for future module enhancements.

Based on this – we need 3 ‘base’ objects – the application, the data model and the module class (all modules must follow a similar form).

Next, we define what we want our application class to control – in this instance, we want the application to control which modules are used, and the navigation to those modules, in addition to user validation and control. We also want it to be able to pass data to the current module in order for the module to be shown correctly (note: I cannot post any code here, because my project is AJAX powered (see http://xajaxproject.com) – which is out of the scope of this article), we also want the application to be able to pass POST data to the modules – so we define methods for the application as such:

Code:
Class Application {
              var $Modules; // class to hold all modules
              var $CurrentModule; // string identifying module
  var $View; // class to control actions on the view (used by modules)
              
    function Application() {
              // whatever code you need to instantiate the object
  }
   
  function Process ($data) {
              // define actions to take when getting a new view
  }
   
  function ProcessForm ($tomodule, $data) {
              // define actions to take when processing a form
  }
   
  }
I would code the user actions under a different class, and link them under Process, as we would any module.

Next you need to define how your modules are called from the application class, and how they return data (ideally they should return data in the View) – ideally, 2 methods should be used – a ‘Run’ method that would allow the module to run based on variables sent to it by the application, and a ‘Post’ method that would control adding data to that modules model..

Once you’ve managed to design this part of the framework, and make sure it’s working – it’s time to set to the interface (or View) – this is relatively simple, as we can have our modules return exactly the kind of data that wont take much jury-rigging to fit.

This is the first in a series of articles on this subject – if it’s helpful – let me know, if you’d like to know more, let me know – and I’ll do another one in a couple of days.

Regards
Sean
__________________
Sean Johnstone

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Tutorials:

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Tutorial on creating navigation tabs using CSS

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Tutorial on PHP custom user authentication
johnboulder is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Old 04-28-2006, 02:32 PM   #2 (permalink)
Moderator
Aficionado
 
Contention's Avatar
 
Join Date: Mar 2003
Age: 31
Posts: 147
Contention is on a distinguished road
Thumbs up

Thanks for the great tutorial
__________________
Misc Tutorials:

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Tutorial on Flash Interval Managers

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Simple Ajax tutorial for beginners

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Tutorial on creating CSS tabs

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Some things you should read before posting
Contention is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Old 04-28-2006, 05:12 PM   #3 (permalink)
Administrator
Enthusiast
 
johnboulder's Avatar
 
Join Date: Mar 2003
Posts: 97
johnboulder is just really nicejohnboulder is just really nice
Send a message via MSN to johnboulder Send a message via Yahoo to johnboulder Send a message via Skype™ to johnboulder
Default

As a footnote - if you're writing your engine in PHP, make ABSOLUTELY sure you get all the names right - yes, I know - that's a beginners mistake, but we all make them.

When dealing with classes of this nature, they can very quickly become very confusing, even for the person who wrote them - so one mis-spelt variable, and you're stuck for hours debugging.
__________________
Sean Johnstone

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Tutorials:

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Tutorial on creating navigation tabs using CSS

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Tutorial on PHP custom user authentication
johnboulder is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Forum Moderator Application Thread danielmichel General Conversation 2 12-25-2006 10:10 PM


All times are GMT -4. The time now is 03:53 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13