LemonInflux Posted April 14, 2008 Share Posted April 14, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/101080-building-an-efficient-php-frameworkmodular-structure-how/ Share on other sites More sharing options...
trq Posted April 14, 2008 Share Posted April 14, 2008 There are many different ways of doing this, one of the most popular is to base your framework around the MVC design pattern. Quote Link to comment https://forums.phpfreaks.com/topic/101080-building-an-efficient-php-frameworkmodular-structure-how/#findComment-516882 Share on other sites More sharing options...
LemonInflux Posted April 14, 2008 Author Share Posted April 14, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/101080-building-an-efficient-php-frameworkmodular-structure-how/#findComment-516984 Share on other sites More sharing options...
Daniel0 Posted April 14, 2008 Share Posted April 14, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/101080-building-an-efficient-php-frameworkmodular-structure-how/#findComment-517101 Share on other sites More sharing options...
LemonInflux Posted April 14, 2008 Author Share Posted April 14, 2008 I beg your pardon? Quote Link to comment https://forums.phpfreaks.com/topic/101080-building-an-efficient-php-frameworkmodular-structure-how/#findComment-517105 Share on other sites More sharing options...
laffin Posted April 14, 2008 Share Posted April 14, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/101080-building-an-efficient-php-frameworkmodular-structure-how/#findComment-517114 Share on other sites More sharing options...
Daniel0 Posted April 14, 2008 Share Posted April 14, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/101080-building-an-efficient-php-frameworkmodular-structure-how/#findComment-517115 Share on other sites More sharing options...
Jenk Posted April 16, 2008 Share Posted April 16, 2008 "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. Quote Link to comment https://forums.phpfreaks.com/topic/101080-building-an-efficient-php-frameworkmodular-structure-how/#findComment-518354 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.