3

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.

2
  • I found that I can do "$route['login'] = '/home/login';" as a route to fix this, but is that the correct way? Is there a better way? Commented Dec 4, 2012 at 14:57
  • well .. the routes are the way to go if you don't like CI standard route behaviour Commented Dec 4, 2012 at 15:12

3 Answers 3

4

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';

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

Comments

0

The way I have it set up is to have the index function act as the gatekeeper: if not logged in, show a login form view, if logged in, redirect to your (protected) home page. The login function is only accessed via post, when the user submits his login/pwd, and performs the login logic.

Comments

0

You need add a line to your application/config/routes.php file

$route['login'] = "home/login";

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.