Welcome Guest, Not a member yet? Register   Sign In
public and private controller
#1

[eluser]Mutsop[/eluser]
Hi,

I have a few controllers which should only be accessed using by logged users.
Now I thought I needed only to set the check (if user is logged in) in the index function of the controller.

Apparently that doesn't work when you try to input the url directly of the other functions.

So i've been reading throughout the web and found out there would be a possibility to use some public or private controller?

Is this correct? and how?

If so, what about if some functions should be able to be accessed and some not in the same controller?
#2

[eluser]WanWizard[/eluser]
Read Phil's article on Base classes...
#3

[eluser]Cristian Gilè[/eluser]
Check if user is logged-in in the controller constructor:

Code:
class Controller_name extends Controller
{
    function __construct()
    {
        parent::__construct();
        if( ! $this->session->userdata('loggedin'))
        {
            //redirect to login page
        }
    }
}

or you can put the check in the admin controller so you don't need to call the condition in every controller constructor:

Code:
class MY_Controller extends Controller
{
    function __construct()
    {
        parent::__construct();
    }
}
Code:
class Admin_Controller extends MY_Controller
{
    function __construct()
    {
        parent::__construct();
        if( ! $this->session->userdata('loggedin'))
        {
            //redirect to login page
        }
    }
}

Non admin pages will extend MY_Controller and admin pages will extend Admin_Controller.

Phil Sturgeon wrote an useful tutorial


Cristian Gilè




Theme © iAndrew 2016 - Forum software by © MyBB