因為需(xu)要(yao)登(deng)錄后(hou)才能瀏覽網站,我在(zai)application/home/controller的Index.php、Lists.php、View.php等控制器文(wen)件(jian)中(zhong)增加如下代(dai)碼,功能已經實現,但總感覺(jue)逐(zhu)個文(wen)件(jian)去添加不合理(li),是(shi)否有其他更好的全局方式,比如在(zai)application/common/controller/Common.php中(zhong)做(zuo)全局判斷?請指教,謝(xie)謝(xie)!
$users_id = (int)session('users_id');
if (empty($users_id)) {
$url = url('user/Users/login');
$this->redirect($url);
}