hyphens2
hyphens2

Reputation: 166

error "404 Page Not Found" in codeigniter

I'm using Codeigniter. I have a class MY_Controller in '/core/MY_Controller.php'

class MY_Controller extends CI_Controller
{
   function __construct()
    {
        parent::__construct();
        echo $controller = $this->uri->segment(1);
    }
}

And class Login.php in \controllers\admin\Login.php

class Login extends MY_Controller{
   function index()
    {
        echo 'login';
    }
}

When i get error 404 when access http://localhost/codeigniter/admin/login/ in browser.

404 Page Not Found

The page you requested was not found.

Any ideas? What am I doing wrong? Thanks C.

Upvotes: 3

Views: 4799

Answers (1)

Maninderpreet Singh
Maninderpreet Singh

Reputation: 2587

TRICK

Add this code to your config file at the top may this code helps you

function __autoload($class)
{
  if (strpos($class, 'CI_') !== 0)
  {
        if (file_exists($file = APPPATH . 'core/' . $class . '.php'))
        {
              include $file;
        }
  }
}

METHOD

You need to set Prefix in your config file

$config['subclass_prefix'] = 'MY_';

htaccess

     RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

ROUTES

$route['default_controller'] = 'YOUR_CONTROLLER';
$route['404_override'] = '';
$route['admin'] = "admin/login";

Upvotes: 3

Related Questions