Airhead315 Posted August 17, 2009 Share Posted August 17, 2009 Ok, So I developed a system which is best referred to as the core system (common components, default configuration...etc). I did not program this using classes (though I should have) because initially this was a very small project but it keeps getting bigger and bigger. My primary navigation into each different section is a case statement: switch($section) { case "Contacts": include a file...do some stuff break; case "Something else": include a file...do some stuff break; } A little more information: Different entitities (which can be added via a database) will use this system and some may need custom sections to be added. Right now the way I handle if they want to modify something in the "Contacts" section is that I create a directory using thier acronym and put a file with the same name as the include file in it. The main system always checks for include '$acronym/contacts.inc' for instance. If it is there it includes it and then it includes the standard contacts.inc. The standard contacts.inc verifys a function is not defined before attempting to define it, so this allows each entity to override certain portions of the system. Any finally, the problem: If an entity wants to add a new section which isnt part of the core system I want to add that to the switch statement without having to have each entitys custom sections included in the main file. In a perfect world I would be able to do something like this: switch($section) { case "Contacts": include a file...do some stuff break; case "Something else": include a file...do some stuff break; injectifexists '$acronym/customSections.inj'; } The customSections.inj would contain something like: case "some custom thing": include a file...do something break; Is there anything I can do to get a similar functionality? Thanks for any and all help, Aaron Quote Link to comment https://forums.phpfreaks.com/topic/170670-including-file-to-extend-switch-statement-options/ Share on other sites More sharing options...
JonnoTheDev Posted August 17, 2009 Share Posted August 17, 2009 MVC pattern http://www.tonymarston.net/php-mysql/model-view-controller.html Quote Link to comment https://forums.phpfreaks.com/topic/170670-including-file-to-extend-switch-statement-options/#findComment-900132 Share on other sites More sharing options...
ignace Posted August 17, 2009 Share Posted August 17, 2009 As Neil already pointed out you need the MVC pattern. However chances are you don't want to write your own MVC. Luckily you are not alone on this planet and millions have written frameworks (meaning that you will get more then you came for) that incorporate the MVC pattern for you. A comprehensive list can be found at Wikipedia: http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller#PHP Before you start tik-tak-to'ing to select your framework. There are a few things you need to know about frameworks. Frameworks come in different forms: Full-stack frameworks: These frameworks gather multiple libraries useful for web development into a single cohesive software stack for web developers to use. These usually also lay the foundation (bootstrap, pre-determined controller directory, ..), examples of these frameworks: - CakePHP - CodeIgniter - .. Component-frameworks or traditional frameworks: - Zend Framework - .. These are the more popular frameworks Quote Link to comment https://forums.phpfreaks.com/topic/170670-including-file-to-extend-switch-statement-options/#findComment-900295 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.