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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:18:14+00:00 2026-06-18T06:18:14+00:00

When I access the wrong function in my controller, a 404 error page is

  • 0

When I access the wrong function in my controller, a 404 error page is working well. But, when i access url like ‘http://example.com/model/detail/116‘, which 116 is wrong number [are not in the database], my 404 error page not working.

I have this code in my controller:

public function detail()
 {
    $id['id_galeri'] = $this->uri->segment(3);
    $detail = $this->app_model->getSelectedData("tbl_galeri",$id);
    foreach($detail->result() as $d)
    {
        $bc['jdl'] = "View";
        $bc['id_galeri'] = $d->id_galeri;
        $bc['nama'] = $d->nama;
        $bc['foto'] = $d->foto;
        $bc['deskripsi'] = $d->deskripsi;
        $bc['stts_input'] = "deskripsi";
    }

    if($this->uri->segment(3) == '' && $id['id_galeri'] == FALSE)
    {
        $segment_url = 0;
    }else{
        if(!is_numeric($this->uri->segment(3)) || !is_string($this->uri->segment(3))){
        redirect('404');
        }else{
        $segment_url = $this->uri->segment(3);
        }
    }

    $this->load->view('frontend/global/bg_top');
    $this->load->view('frontend/page/bg_view_model',$bc);
    $this->load->view('frontend/global/bg_footer');
}

Sorry for my bad english, please help 🙂
Thank you..

  • 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-18T06:18:16+00:00Added an answer on June 18, 2026 at 6:18 am

    Instead of:

    redirect('404');
    

    try using CodeIgniter’s native:

    show_404('page');
    

    EDIT

    Try this code, a bit cleaned up and the checks are done before they’re saved for views use.

    public function detail()
     {
        $id['id_galeri'] = $this->uri->segment(3);
    
        // Check if the supplied ID is numeric in the first place
        if ( ! is_numeric($id['id_galeri']))
        {
            show_404($this->uri->uri_string());
        }
    
        // Get the data
        $detail = $this->app_model->getSelectedData("tbl_galeri",$id);
    
        // Check if any records returned
        if (count($detail->result()) === 0)
        {
            show_404($this->uri->uri_string());
        }
    
        foreach($detail->result() as $d)
        {
            $bc['jdl'] = "View";
            $bc['id_galeri'] = $d->id_galeri;
            $bc['nama'] = $d->nama;
            $bc['foto'] = $d->foto;
            $bc['deskripsi'] = $d->deskripsi;
            $bc['stts_input'] = "deskripsi";
        }
    
        /**
         * Here do whatever you want with the $segment_url which doesn't seem to be
         * used in your code
         */
    
        $this->load->view('frontend/global/bg_top');
        $this->load->view('frontend/page/bg_view_model',$bc);
        $this->load->view('frontend/global/bg_footer');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to set-up a call back function, but it's not working for some reason.
Access denied for user 'root '@'localhost' (using password: YES) Yes, this error is all
Access modifiers like public , private are not allowed on static constructors in C#.
ms-access is connecting to a local mysql database the following code returns an error:
i have a problem with the function mkdir() i get that error message: Warning:
The routine below in Access 2003 produces error 7961 -- My database 'can't find
Hello all im working on a project but when i upload my project i
i am writing a kohana controller, and i am constantly getting a weired error,
I have a application/controller/login.php file containing the following class Login extends Controller { function
I've found alot of questions like this one around the site but none of

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.