Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter "default_controller" functions without controller name in URL

Forgive me if this is a "duh" question or if you need more information to answer, I am new to CodeIgniter and still haven't figured out a few things with best practices and such...

In routes.php I have $route['default_controller'] = "home"; so my default_controller is obviously "home".

Inside my home.php controller I have:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
    function __construct() {
        // blah
    }
    function index(){
        // blah
    }
    function login(){
        // blah
    }
}

Which works fine and everything, there is no problems with that. The only thing I can't figure out is if I want to access the login function, I currently have to go to www.blah.com/home/login. How can I change it so it just goes to www.blah.com/login, without creating a new controller (I would like to keep some of these one time base urls all in my default controller)? Is that even possible or do I just have to create a new controller?

If I just have to create a new one, is there a best practices for how many controllers you have, etc.

like image 405
Zach Reed Avatar asked Dec 30 '25 03:12

Zach Reed


1 Answers

Documentation says: This route will tell the Router what URI segments to use if those provided in the URL cannot be matched to a valid route.

So use $route['login'] = 'home/login';

like image 112
Waqar Alamgir Avatar answered Dec 31 '25 17:12

Waqar Alamgir