简体   繁体   中英

Does CodeIgniter call a controller's constructor when calling one of its methods via AJAX?

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 :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM