CI项目架构(2)---共用model、library、helper

新建公共文件夹



启用钩子

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 文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值