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

  • Home
  • SEARCH
  • 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 376135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:34:11+00:00 2026-05-12T14:34:11+00:00

I am using a Front Controller to send the user through a series of

  • 0

I am using a Front Controller to send the user through a series of pages with questions. Pretty much everything must be dynamic as the pages, the questions, and everything else is set in the admin interface and stored in the database.

I am tracking the user’s progress through the database by storing a unique identifier in the session and storing the current page the user is on in the database so I can figure out the next page to send them to.

The thing is, there are a lot of special cases to check for. Right now the controller is over 300 lines long and the code is poorly written and I’m the one who wrote it. Plus, I am going to need to add a lot more to this system in the upcoming weeks such as user-generated content and different pages to show depending on where the user is coming from.

I can see that this controller is going to become a big mess fast if I don’t organize it well.

What are some good ways or ideas to refactor this?

  • 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-12T14:34:11+00:00Added an answer on May 12, 2026 at 2:34 pm

    Generally it’s easier to use URLs to determine what you should send to the client. If your questions are submitted via a <form> you can return a redirect to the next question once you have saved the answer. For example if this was one of your questions:

    <form action="/questions/14" method="post">...
    

    This would submit to /questions/14 and once you have saved the answer you can redirect to question 15:

    header('Location: /questions/15');
    exit;
    

    Once you have URLs in place you can split up your front controller into parts that relate to each question. Then all you need is some routing:

    if(preg_match('/\/questions\/([0-9]+)/',$_SERVER['REQUEST_URI'],$matches) > 0) 
    {
        $question_num = (int)$matches[1];
        if(!in_array($question_num, $valid_questions)) {
            // return 404
        }
    
        $controller_name = 'Question_' . $question_num;
        return new $controller_name; 
    } 
    else // check for urls that aren't questions ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 205k
  • Answers 205k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Why do you want to use Google Earth? It can't… May 12, 2026 at 8:58 pm
  • Editorial Team
    Editorial Team added an answer Install your scripts with the normal CPAN tools. During the… May 12, 2026 at 8:58 pm
  • Editorial Team
    Editorial Team added an answer From the documentation it seems you need associative arrays. Can… May 12, 2026 at 8:58 pm

Related Questions

I currently use CodeIgniter as my framework of choice when using PHP. One of
I am using a shared hosting through CIPL.in. They use cpanel. I am trying
I'm using a very simple MVC framework, Bear Bibeault's Front Man , which, for
So I've got a simple web application using Spring MVC + Hibernate and am
I am using the mod-rewrite router. I am trying to add a Route to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.