CodeIgniter - How to check session to be used at every methods

前端 未结 3 1085
无人及你
无人及你 2021-01-05 09:27

Let say at my controller named Book, I have many methods, such as get_book(); read_book(); remove_book();

<
3条回答
  •  死守一世寂寞
    2021-01-05 09:56

    You don't necessarily need to do that. Simply put the login check code in the constructor and you're all set!

    class Book extends CI_Controller
    {
        public function __construct()
        {
            if ($this->is_logged_in())
            {
                // redirect to home
            }
        }
    
        public function get_book()
        {
            ...
        }
    
        // The rest of the code...
    }
    

提交回复
热议问题