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 952411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:53:26+00:00 2026-05-15T23:53:26+00:00

I’m working on a humble website with my mediocre, self-taught PHP skills, and the

  • 0

I’m working on a humble website with my mediocre, self-taught PHP skills, and the current interface structure is like this:

<?php
  if (A) {
    $output = someFunc(A);
  } else if (B) {
    $output = anotherFunc(B);
  } else if (C) {
    $output = yetAnotherFunc(C);
  } else {
    $output = 'default stuff';
  }
?>
<html template top half>

<?php echo $output; ?>

</html template bottom half>

This worked ok at first, and seemed pretty well organized, but the functionality required has grown by a factor of 10 and it’s rapidly turning into an unmaintainable, embarrassing mess and I don’t know how to get out of it.

I feel that the functions being called for each situation are fairly well-written and focused, but am at a loss as to how to handle the middle-step between the user and the functions that creates the layout and handles the return.

I have a feeling that MVC is one solution? But I’m having a hard time grasping how to go from here to there…

I apologize for any headaches or unpleasant memories the above code may have prompted. Thank you for your time.

  • 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-15T23:53:27+00:00Added an answer on May 15, 2026 at 11:53 pm

    You seem to have started the way a lot of people do, a big if and/or case statement that continues to grow. All those “if” checks can take time. MVC is definitely a great way to go, but there are so many ways to implement it. I would recommend also looking to the Front Controller design pattern, which is commonly used with MVC.

    One way to change how you are doing things is to switch to a defined list of “actions” using an associative array. And change your functions into includes. Then you can have multiple functions, variables and other processing code.

    $actions = array(
    'A'=>'action1.php',
    'B'=>'action2.php',
    'C'=>'action3.php',
    'default'=>'action_default.php'
    );
    if ( isset( $actions[ $_GET['action'] ] ) ) {
        include( $actions[ $_GET['action'] ] );
    } else {
        include( $actions['default'] );
    }
    

    Then your “index” file is just a routing tool, which is pretty much the Front Controller concept.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace

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.