views:

21

answers:

1

I need to know whether I should re-call my helper redirectIfNotLoggedIn() inside ajaxFunction, since it's already in the constructor:

class Group extends Controller {
    function Group() {  
        parent::Controller();
        redirectIfNotLoggedIn();
    }
    function ajaxFunction() {
        //I am called via AJAX
        //Do I need to call redirectIfNotLoggedIn() again?
        //Or is the constructor called whenever I access this function via AJAX?
    }
}

Any help would be appreciated :)

+1  A: 

An Ajax request is nothing more than an HTTP request to your CodeIgniter application, except that it's sent by JavaScript. So your controller will still be instantiated and run as usual.

Your controller's constructor will be invoked and redirectIfNotLoggedIn() called, so you don't need to call it again.

BoltClock
This is correct. One problem I've had in the past though is if there's a small part of the page being loaded via ajax and you're redirected to a login page (just a simple form) then the form will appear wherever the content was supposed to. Make sure you watch for that.
Matthew