Jump to content

Including file to extend switch statement options


Airhead315

Recommended Posts

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

Link to comment
Share on other sites

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

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.