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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:10:11+00:00 2026-06-07T07:10:11+00:00

I am using the HMVC pattern in CodeIgniter. I have a controller that loads

  • 0

I am using the HMVC pattern in CodeIgniter. I have a controller that loads 2 modules via modules::run() function and a parameter is passed to each module.

If either module cannot match the passed paramter I want to call show_404(). It works, but it loads the full HTML of the error page within my existing template so the HTML breaks and looks terrible. I think I want it to redirect to the error page so it doesn’t run the 2nd module. Is there some way to do that and not change the URL?

Is it possible to just redirect to show_404() from the module without changing the URL?

Here is an over simplified example of what’s going on:

http://www.example.com/users/profile/usernamehere

The url calls this function in the users controller:

function profile($username)
{
    echo modules::run('user/details', $username);
    echo modules::run('user/friends', $username);
}

Which run these modules, which find out if user exists or not:

function details($username)
{
    $details = lookup_user($username);
    if($details == 'User Not Found')
        show_404(); // This seems to display within the template when what I want is for it to redirect
    else
        $this->load->view('details', $details);
}

function friends($username)
{
    $details = lookup_user($username);
    if($friends == 'User Not Found')
        show_404(); // Redundant, I know, just added for this example
    else
        $this->load->view('friends', $friends);
}

I imagine there is just a better way to go at it, but I am not seeing it. Any ideas?

  • 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-06-07T07:10:13+00:00Added an answer on June 7, 2026 at 7:10 am

    You could throw an exception if there was an error in a submodule and catch this in your controller where you would do show_404() then.

    Controller:

    function profile($username)
    {
        try{
           $out  = modules::run('user/details', $username);
           $out .= modules::run('user/friends', $username);
           echo $out;
        }
        catch(Exception $e){
           show_404();
        }
    }
    

    Submodule:

    function details($username)
    {
        $details = lookup_user($username);
        if($details == 'User Not Found')
            throw new Exception();
        else
            // Added third parameter as true to be able to return the data, instead of outputting it directly.
            return $this->load->view('details', $details,true);
    }
    
    function friends($username)
    {
        $details = lookup_user($username);
        if($friends == 'User Not Found')
            throw new Exception();
        else
            return $this->load->view('friends', $friends,true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using HMVC in CodeIgniter https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home How do I setup a controller that would
I am using Codeigniter 1.7.2 and HMVC (https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home). I have these files and they
I have setup a fresh install of codeigniter 2x and modular extensions (https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home) It
I'm using HMVC and calling modules in a view. In some cases however, the
Using report builder 3.0, I have a report that queries a cube. How do
I'm using MVC pattern for web development. I use codeIgniter framework. I found http://fuelphp.com/
Using CRM 4, I have an entity form that contains a tab with an
the PHP framework I am using (Kohana) recently implemented the HMVC architecture. I have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I am using HMVC codeigniter. I am trying to use jquery ajax first time.

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.