Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6832957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:55:18+00:00 2026-05-26T22:55:18+00:00

What solutions,patterns usually used for this? I want to get rid of if/else statements

  • 0

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”. 😀

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:55:18+00:00Added an answer on May 26, 2026 at 10:55 pm

    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:

        class yourClass
        {
            protected $_strategy;
    
            public function setStrategy($strategy)
            {
                $this->_strategy = $strategy;
            }
    
            public function showYourData()
            {
                return $this->_strategy->show($this)
            }
        }
    

    For each domain you build a separate strategyclass as follows:

        class domainStrategy
        {
            public function show(yourClass $yourClass)
            {
                 // Get your classdata here
                 $data = $yourClass->whateverFunctionYouNeed();
                 // Do what you want for this domain
                 return $output;
            }
        }
    

    I hope this gets you started, I’m sure you can find more documentation for the strategypattern when you need it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What solutions do I have if I want to prevent the UI from freezing
I have seen solutions like this: kernel dp_square (const float *a, float *result) {
Hi! I am trying to find some optimal solutions in C++ coding patterns, and
After hours looking for solutions and patterns, it's time for me to ask the
I have tried many of the solutions in this website to solve the issue
We usually use builder pattern in java, like this: UserBuilder userBuilder = new UserBuilder();
In C# from time to time the issue creeps out. Usually I get an
Following is excrept from this article on MVVM. Can someone provide example of how
I have found many solutions on how to match multiple patterns in string, but
I want to create gallery application which would get thumbnails and metadata from web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.