What solutions,patterns usually used for this?
I want to get rid of if/else statements in my controllers, models and so on.
For example:
if($domain==1) {
// do this
}
elseif($domain==2) {
// do this
}
elseif...
Want to get rid of this madness. Can’t imagine what mess will be, when there will be at least 20 websites.
Currently i’m using config and routing files for each domain. But that’s not enough.
Can’t get rid of this mess inside models and controllers.
I was thinking about some kind of placeholders and separate static class for each domain with method for those placeholders + magic calls.
For example i have action inside controller:
public function postAction(){
$model=new Model();
$this->view->data=$model->get($placeholder_generates_and_return_settings_array); // else default is used
// custom placeholder
// execute custom class method if it's exist
// some model again
// custom placeholder
// execute custom class method if it's exist
// etc
}
Current view is provided inside placeholders Class, types can be assigned. Like data modification, config generation for model etc.
How would you resolve this issue with multiple domains, without cloning controllers, models or creating innumerous if/elseif statements for each domain inside them?
UPDATE
How to describe what i need. I’m trying to create reusable controllers with default logic in it. Just filling/MIXING controller with domain related logic in required places(placeholders), data modification etc. Something like controller-template possible, any patterns exist?
Providing placeholder with all required(CURRENT) data for it’s modification if required or further processing AND returning it back.
Guess i’ll have to create my own “bicycle”. 😀
Based on the information you provide I assume that you wish to display your data differently based on the domain. Also assuming that your data remains unchanged you could use a strategy pattern to solve your problem.
Your class structure would then look as follows:
For each domain you build a separate strategyclass as follows:
I hope this gets you started, I’m sure you can find more documentation for the strategypattern when you need it