user3651476
user3651476

Reputation: 171

Error: A default route has not been specified in the routing file in CI 3.0

I have successfully run the test webpage in my local machine and it works! But when I uploaded it to the production server (iPage), I got this error:

An Error Was Encountered
Unable to determine what should be displayed. A default route has not been specified in the routing file.

I have here the .htacess file:

 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond $1 !^(index\.php|assets|img|bg|robots\.txt)
 RewriteRule ^(.*)$ index.php?/$1 [L] 

Outside the application folder.

and in my routes.php:

$route['default_controller'] = 'login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

and in my config.php:

$config['base_url'] = 'http://example.com/System';
$config['uri_protocol'] = 'REQUEST_URI';
$config['enable_query_strings'] = TRUE;

I have login.php inside controller folder with the ff codes:

 defined('BASEPATH') OR exit('No direct script access allowed');

class login extends CI_Controller {
    function __construct() {
        parent::__construct();
        $this->load->model('login_model');
        /* enable session */
        $this->load->library('session');
    }

 public function index()
    {
        if ( ! file_exists(APPPATH.'/views/index.php'))
        {
            /* Whoops, we don't have a page for that! */
               show_404();

        }

        $this->load->view('index'); 
       $this->load->view('templates/footer');   

   }    

Am I missing or did something wrong?

Upvotes: 3

Views: 13770

Answers (2)

Narf
Narf

Reputation: 14762

CodeIgniter 3 requires that your classes are named in a Ucfirst manner and the filenames must match the class names.

Therefore, you need to rename your 'login.php' to 'Login.php', as well as change the class declaration to class Login extends CI_Controller.

Upvotes: 2

Abdulla Nilam
Abdulla Nilam

Reputation: 38652

Your routes contain

$route['default_controller'] = 'login';

So in controller page name should be login.php

Inside login.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class Login extends CI_Controller//check this
    {
        public function  __construct()
        {
            parent::__construct();
    }

Brief: check this class Login extends CI_Controller

And base_url should be

$config['base_url'] = '';

Upvotes: 0

Related Questions