2

I want to create a simple user system in codeigniter. I have created two controller called admin and login. When user visit my website i.e http://example.com it shows the login page if the user is not logged in. After that when user logged in it redirects to admin page.

But I want to know which controller I should make as a default controller admin or login?

N.B- I am new in codeigniter. I know how MVC works.

2 Answers 2

2

your default controller should be login.

In application/config/routes.php,

$route['default_controller'] = "login controller name";

In login controller's constructor, check if the user is already loggen in'

        if(user alerady logged in){
            redirect("admin controller's name");//redirect to admin controller
        }
Sign up to request clarification or add additional context in comments.

2 Comments

If user already logged in then i need to redirect to admin page? right?
yes, in login controller check this in constructor, if the user is logged in or not.
2

In application/config/routes.php

Replace

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

To

$route['default_controller'] = "login"; //or whatever you want 

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.