1

I have been working with codeigniter for a long time. I have set my default controller to:

$route['default_controller'] = "main";

everything is fine, except I have created a function in main.php controller file that redirects to 404 Not Found page.

This is my code in main.php:

function not_found()
{
    $data['page_Title'] = '404 Error!';
    $data['page_Description'] = 'Description';
    $data['page_Keywords'] = 'Keywords';
$data['main_content'] = 'not_found';
    $this->load->view('includes/template', $data); 
}

Then when I want to load example.com/not_found/ it redirects me to the codeigniter's default not found page and says:

404 Page Not Found

The page you requested was not found.

but, there is no problem requesting the page like:

example.com/main/not_found/

Do I have to set another route like:

$route['not_found'] = "main/not_found";

?! but this is not a good way I think!

1
  • 1
    Yes, you have to setup that route to map the "not_found" method to the main.php controller else it'll throw the default CI 404 error. Commented Sep 9, 2013 at 9:27

2 Answers 2

2

The url format of CI describes :

domain.com/controller/method

And not:

domain.com/method

If you have a index function in your controller then that function will be called like this:

domain.com
Sign up to request clarification or add additional context in comments.

3 Comments

so I have to set another route?!
I you want to chnage the 404 error then change this line in your application/config/routes.php : $route['404_override'] = 'main/not_found';
no of course I don't want to do it because routing 404_override is both for admin section and user side. but my templates differs in them! But I got what to do! thanks
1

example.com/not_found/ mean, codeIgniter will find controllers/not_found.php and execute function index()

You have to create controllers/not_found.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.