Welcome Guest, Not a member yet? Register   Sign In
Auto load Library before all Controllers
#1

[eluser]Ty Bex[/eluser]
I would like to make a library available to all contollers.

My Library is in the application/libraries/Auth_user.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Auth_user{
    
    function Auth_user()
    {
        $CI =& get_instance();
        $CI->load->database();
        $CI->load->library('session');
        $CI->load->library('encrypt');
        $CI->load->library('validation');
        $CI->load->helper('form');
    }
    
    function check($check_level)
    {
      /*DO SOME CHEKCING*/
    }
}

Currently my controller is /application/controllers/backend/welcome.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();
        $this->load->library('auth_user');
        $this->auth_user->check('admin');
    }
    
    function index()
    {
        echo "<br />BACKEND WELCOME.PHP<br />SUCCESS TO INDEX FUNCTION<br /><br />";
    }
}


What I want to do is just call the library and not have to load the library for every page. (Commented out line)
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();
        /*$this->load->library('auth_user');*/
        $this->auth_user->check('admin');
    }
    
    function index()
    {
        echo "<br />BACKEND WELCOME.PHP<br />SUCCESS TO INDEX FUNCTION<br /><br />";
    }
}

I am not 100% where to go with this one...Thanks in advance


Messages In This Thread
Auto load Library before all Controllers - by El Forum - 12-03-2008, 10:48 PM
Auto load Library before all Controllers - by El Forum - 12-03-2008, 11:21 PM
Auto load Library before all Controllers - by El Forum - 12-04-2008, 12:46 AM
Auto load Library before all Controllers - by El Forum - 12-04-2008, 09:01 AM
Auto load Library before all Controllers - by El Forum - 12-04-2008, 12:07 PM



Theme © iAndrew 2016 - Forum software by © MyBB