activate_helper.php 937 Bytes
<?php

defined('BASEPATH') OR exit('No direct script access allowed');

if(!function_exists('activate')) {
    function activate($url) {
        return uri_string() == $url;
    }
}

if(!function_exists('api')) {
    function api($url) {
        $CI = &get_instance();
        $url = $CI->config->item('apiBaseUrl') . $url;
        $result = file_get_contents($url);
        $json = json_decode($result);
        $ret = $json->data;

        return $ret;
    }
}

if(!function_exists('hasRole')) {
    function hasRole($roles = []) {
        $CI = &get_instance();
        $CI->load->helper('cookie');
        $login_user = get_cookie('login_user');
        if($login_user) {
            $login_user = json_decode($login_user, true);
            foreach($login_user['roleKeys'] as $v){
                if(in_array($v, $roles)){
                    return true;
                }
            }
            return false;
        }
    }
}