新建公共文件夹
启用钩子
config->config.php
$config['enable_hooks'] = true;
config->hooks.php
$hook['post_controller_constructor'] = array(
'class' => 'Auth',
'function' => 'index',
'filename' => 'auth.php',
'filepath' => 'hooks',
);
hooks->Auth.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* 权限控制
*/
class Auth{
private $CI;//超级对象
private $allow = array('release');//需要验证登录的控制器
private $deny = array('register');//注册后不允许访问的控制器
public function __construct() {
$this->CI =&get_instance();
//共享 model library helper
<span style="color:#ff0000;">$url = dirname(BASEPATH) . '/application/bbspublic/';
$this->CI->load->add_package_path($url);</span>
}
/**
* 登陆判断
*/
public function index() {
$tmp = explode('/', uri_string());
if (in_array($tmp[0], $this->allow) && ! isset($_SESSION['logininfo'])) {
show_error('您没有登录!<a href="/">返回首页登录</a>');
}
}
}
删除前后台的model library helper 文件