Jump to content

Building an efficient PHP framework/modular structure - how??


LemonInflux

Recommended Posts

Hello. I've been developing some wiki-type software as a hobby, and I've been tidying up the code.

 

However, I would like to make it more efficient to build on.

 

I've seen software such as gallery that has a very modular structure, and I can't figure out how they've done it.

 

What I'm basically asking for is an efficient way of doing this? The theory behind it, I mean. I can code it and stuff, but how is it actually done?

 

How is it laid out etc.

 

Thanks in advance,

 

Tom

Link to comment
Share on other sites

I've read through that, but there is still something I don't understand.

 

Within my modules, how do I tell the script my module wants to edit, say, a menu, or add a link somewhere on the page? Do I need to define categories for every single module? How does the script distinguish one module's position from the next?

Link to comment
Share on other sites

The MVC pattern often goes along with the front controller pattern. You'd have the front controller as an intermediate between the user request and the page controller, so it is the one which is responsible for picking the right page controller and call the right method in that controller. Sometimes, parsing the URL is delegated to a routing class which would for instance turn /profile/Daniel0 into information needed to pick the right controller (e.g. "UsersController") and the right method within that (e.g. "UsersController::profileAction()") as well as any parameters specified in the URL. The routes could be a combination of default routes and specialized/custom routes like the previous example.

Link to comment
Share on other sites

U have to put thought into yer layouts.

and use a weighted/positional system.

 

so say in yer layuout, u have 3 positons

 

left,center,right

 

now, we want menu on left side very top

 

we wud design our db to use this type of info.

 

TABLE

  id integer

  position tinyint

  menuposition tinyint

  module  varchar

 

 

position, u can assign

0 = left

1 = center

2 = right

according to yer layout

 

menuposition, u assign where it goes

 

so say u have a login_box and a navmenu as modules, and u want them both on left side

with login_box always on top

 

  id  position  menuposition  module

  0  0            1                navmenu

  1  0            0                login_box

 

now when u go thru the db, remeber to SORT BY menuposition ASC

so the login_box always comes first, no matter what id it has

 

Link to comment
Share on other sites

Ok... let me try to rephrase that...

 

[user Request]

      |

      |

      v

Frontcontroller <-------> Router

      |

      |

      v

PageController <-----> Model

      |

      |

      v

     View

 

So first the user makes a request. Information about the request is sent to the front controller which delegates various tasks to other classes such as the router class. The router class' task would here be to extract information from the URL that is required in order for the front controller to call the right page controller. So if we follow a convention of /controller/action, /users/list would go to the users controller, and the list action (i.e. something like UsersController::listAction()). The router would pass this information back to the front controller and the front controller would then create a new instance of UsersController and then call the listAction(). Upon instantiation of the page controller object, the front controller could possibly also forward various information. That could for instance be any parameters (e.g. if the URL had been /user/view/1, the 1 could have been a parameter, a user id). The page controller then calls the model which would get the list of all users, and the page controller would then give the view that information. The view then figures out how to make this data, which came from the model via the page controller, into whatever way the user is supposed to see it.

 

That's how the MVC pattern and Front Controller pattern often works together.

Link to comment
Share on other sites

"Modular" just means that every class/object is concise and only encapsulates one type of behaviour, so that this maximises reusability. If you have an object that is too specific in the way it must be used, you'll be very restricted.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.