0

Hi I'm new to codeigniter. I have installed codeigniter on Ubuntu 14.04 and I'm able to see the welcome page. However other controllers that I create are not working.

I get a message the page not found. I have looked around a lot but could not find anything to fix my issue.

Can anyone kindly help?

class Login extends CI_Controller {

public function __construct() {
    parent::__construct();
    $this->load->helper('url');
    $this->load->library('email');
    $this->load->helper('form');
    $this->load->library('form_validation');
    $this->load->library('session');
    $this->load->model('login_model');
}

public function index($msg = NULL) {
    $data['msg'] = $msg;
    if ($this->session->userdata('validated') == false) {
        $this->load->view('templates/header_login');
        $this->load->view('login_view', $data);
        $this->load->view('templates/footer');
    }
    else {
        redirect('home', 'refresh');
    }
}

Routes.php

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

The default codeigniter page works completely fine. But If I change the default controller with mine then I get a message that page not found

krish_cloudnow
  • 180
  • 1
  • 13

3 Answers3

1

Whenever you install Codeigniter,

You can always access any controller, with http://sitename/index.php/controller/method/parameter. You remove index.php from url with .htaccess file.

You can access your login page with http://sitename.com/index.php/login

Sample .htaccess code: RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L]

Pupil
  • 23,834
  • 6
  • 44
  • 66
0

To access your custom controller all you have to do is use index.php in your URL. Such as if your controller name is User the use this url http://localhost/your_project/index.php/user

and if you want to go any other method in User controller like create then use

http://localhost/your_project/index.php/user/create

But if you don't like to see index.php in your URL then you may place a file in your root directory name .htaccess and put followings in this file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Ref: More Details

now your URL looks like http://localhost/your_project/user/create

Rejoanul Alam
  • 5,435
  • 3
  • 39
  • 68
0

Codeigniter works like this

www.yourdomain.com/controller/function

if you add index function in your controller you can visit directly

www.yourdomain.com/controller/

check that you added index function

Please add .htaccess in your project root

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /stock
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</IfModule>