Afshin
Afshin

Reputation: 2437

default_controller route does not work with a function not_found in codeigniter

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!

Upvotes: 1

Views: 786

Answers (2)

zerokavn
zerokavn

Reputation: 1333

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

You have to create controllers/not_found.php

Upvotes: 1

Nil'z
Nil'z

Reputation: 7475

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

Upvotes: 2

Related Questions