Welcome Guest, Not a member yet? Register   Sign In
One if statement to rule them all
#7

[eluser]Phil Sturgeon[/eluser]
+1 for MY_Controller. On PyroCMS I use several types of controller classes. MY_Controller adds logic to ALL controllers then I have Public_Controller and Admin_Controller to add shared logic to the front and back ends respectively.

If you just want to do this on a per-controller basis or don't want the extra complication, just do this:

Code:
class something extends Controller {
    function something() {
        parent::Controller();

        if($this->session->userdata('logged_in') === FALSE)
        {
            redirect('/');
        }
    }

    function main()
    {
        $data['username'] = $this->session->userdata('email');
        $data['firstN'] = $this->session->userdata('first_name');
        $data['lastN'] = $this->session->userdata('last_name');
        $data['city'] = $this->session->userdata('city');
        $data['state'] = $this->session->userdata('state');
        $this->load->view('mrmain/includes/header_view');
        $this->load->view('admin/main_view', $data);
        $this->load->view('mrmain/includes/footer_view');
    }
    
}


Messages In This Thread
One if statement to rule them all - by El Forum - 09-08-2009, 06:36 PM
One if statement to rule them all - by El Forum - 09-08-2009, 07:43 PM
One if statement to rule them all - by El Forum - 09-08-2009, 07:50 PM
One if statement to rule them all - by El Forum - 09-08-2009, 08:08 PM
One if statement to rule them all - by El Forum - 09-08-2009, 08:15 PM
One if statement to rule them all - by El Forum - 09-09-2009, 12:10 AM
One if statement to rule them all - by El Forum - 09-09-2009, 01:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB