2

I will try to define index controller as a default controller

I will also change routes.php file

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

but it did not work when i define welcome or other controller name like admin so it will work

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

or

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

my url is

http://localhost/ciDemo/

if default_controller is admin or welcome it will work but default_controller is index so error will be given

404 Page Not Found

The page you requested was not found.

if there any way to use index controller as a default controller

my controller file is bellow:

Admin
Index
Welcome
2
  • 1
    Show us your code of index controller. Issue must be in index controller Commented Jun 15, 2017 at 12:07
  • create new page user.php(in view) and $this->load->view('user'); replace in index. Commented Jun 15, 2017 at 12:17

2 Answers 2

5

Controller names

Since your controller classes will extend the main application controller you must be careful not to name your methods identically to the ones used by that class, otherwise your local methods will override them. The following is a list of reserved names. Do not name your controller any of these:

CI_Controller

Default

index

Taken from codeigniter 3 documentation

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

Comments

0

As @Dale said you can not use some of reserve keywords for controller. But if you still want to use index controler add __construct() in controller

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

class Index extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function __construct()
    {
        parent::__construct();       
    }

    public function index()
    {
        $this->load->view('welcome_message');
    }
}

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.