之前并不想修改内核代码,因为想考虑升级,
所以使用了在控制器的__construct进行检测是否登录,然后再设置标志变量,接着在方法中检测此变量,如果未登录就中止方法执行,载入登录页面.
因为同时不想使用浏览器重新定位跳转方法.
现在看一下代码.
修改内核方法是
在system/core/codeigniter.php中找到
// Call the requested method.
// Any URI segments present (besides the class/function) will be passed to the method for convenience
call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
在
call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
加上
if (empty($breakCtr))
$breakCtr是在控制器的初始化时检测登录状态设置的标志,如果发现未登录,也就不再调用方法了.
标志位是在方法执行前设置
global $breakCtr;
$breakCtr = 1;
如在本类的初始化中.
第三种方式那就是让浏览器跳转了.可能这种方式是最好了吧,不改内核,又能方便统一检测处理登录状态.