Welcome Guest, Not a member yet? Register   Sign In
Variables in all areas
#3

(This post was last modified: 04-08-2015, 07:52 AM by sintakonte.)

yeah i know that


but i was looking for some more flexible method because i've some objects in my session and i don't want to access them via $this->session->userdata(blabla) (because of the fact that it is too long)

so i was looking for a handsome method 

what i did so far is the following:

Creating a hook - for example:
Hooks.php :


PHP Code:
$hook['pre_controller'][] = array(
    
'class' => 'AppAutoLoadObjects',
    
'function' => 'initialize',
    
'filename' => 'AppAutoLoadObjects.php',
    
'filepath' => 'hooks'
); 


AppAutoLoadObjects.php:

PHP Code:
class AppAutoLoadObjects {

    private 
$ci;

    public function 
__construct()
    {
        
$this->ci = &get_instance();
    }

    public function 
initialize()
    {
        
$ur = new stdClass();
        
$ur->exampleVar 1;
        
$this->ci->ur $ur;
    }





In this example - i have access to $this->ur in all models, controllers and views (basically in my entire CI environment)
But i don't really know if this is a good way to accomplish what i want

Basically the main reason for this question is, i need quick access to some objects (approx. 5) which should be globally available
Reply


Messages In This Thread
Variables in all areas - by sintakonte - 04-08-2015, 06:57 AM
RE: Variables in all areas - by sv3tli0 - 04-08-2015, 07:13 AM
RE: Variables in all areas - by sintakonte - 04-08-2015, 07:49 AM
RE: Variables in all areas - by cartalot - 04-08-2015, 08:47 AM
RE: Variables in all areas - by CroNiX - 04-08-2015, 09:11 AM
RE: Variables in all areas - by cartalot - 04-08-2015, 04:19 PM
RE: Variables in all areas - by sintakonte - 04-09-2015, 12:45 AM
RE: Variables in all areas - by ivantcholakov - 04-09-2015, 06:57 PM
RE: Variables in all areas - by sintakonte - 04-10-2015, 01:39 AM
RE: Variables in all areas - by ivantcholakov - 04-10-2015, 12:12 PM
RE: Variables in all areas - by ivantcholakov - 04-10-2015, 03:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB