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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:41:16+00:00 2026-05-15T14:41:16+00:00

In a PHP MVC framework, how can I cleanly and elegantly exit from the

  • 0

In a PHP MVC framework, how can I cleanly and elegantly exit from the current controller/action, but continue normal script execution?

For example, let’s say my framework normally follows this outline:

  1. Map URL to Controller/Action
  2. Instantiate Controller, call Action (capturing output)
    1. Do stuff
    2. Render View
    3. At end of Action method, continue normal operation
  3. Process output if necessary
  4. Send output to browser

Now, let’s say I want to stop “normal” execution somewhere in the “Do Stuff” step to, say, render a different view, or do a header redirect, and I want to stop processing the rest of the body of the Action, but continue onto the “Process output” step

How can I achieve this the best way? My only ideas are:

//in controller
protected function redirect($url) {
    header("Location: $url");
    exit();
}

but this entirely skips the rest of the framework’s execution, and dumps whatever was in the output buffer straight to the user. An alternative:

//in dispatcher
call_user_func_array(array($controller,$action),$params);
afterwards:
...

//in controller
protected function redirect($url) {
    header("Location: $url");
    goto afterwards;
}

However, this makes me twitch and goes against everything I’ve learned, especially because the label it’s referencing is in another file completely.

So, is there any other way to achieve this?

Note: The redirect example probably should use the exit() way, because we’re just redirecting to another page anyway and don’t care about output. I’m looking for a general-use solution.

  • 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-15T14:41:16+00:00Added an answer on May 15, 2026 at 2:41 pm

    In your Action method, you can collect all of your output in a string rather than printing it out. Print it out only at the end of the method. If you need to redirect or bail out, then you haven’t output anything yet and you can either redirect or return from the method.

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

Sidebar

Related Questions

I'm making a small PHP MVC framework for fun. I'm using a front controller
I'm developing an MVC framework in PHP from scratch; mostly for the learning experience
I need to call a Kohana helper (or any php MVC framework) from a
I am working on an MVC framework in PHP but I work with java
I made a small MVC Framework, but i need that my view Class can
I am developing a php MVC framework from scratch and have run into an
I am currently developing a PHP MVC Framework for a personal project. While I
I'm trying to write a simple PHP MVC framework to play with. Right now,
I have just started out with testing some php mvc framework In it, it
For class, I would like a to use PHP MVC framework very similar to

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.