Welcome Guest, Not a member yet? Register   Sign In
Accessing CI object from Library
#1

Hi, 
most of the times I see CI object is accessed from library in following way:

PHP Code:
$ci = &get_instance(); 

But in Codeigntier Ion Auth library they accessed as if they not in library.
Here is contructor of Ion Auth Library.
PHP Code:
    public function __construct()
    {
        
$this->config->load('ion_auth'TRUE);
        
$this->load->library(array('email'));
//...


How it is accessed using $this in this library?
The link to code: https://github.com/benedmunds/CodeIgnite...n_auth.php
Reply
#2

It's using the php magic method __get()

PHP Code:
/**
     * __get
     *
     * Enables the use of CI super-global without having to define an extra variable.
     *
     * I can't remember where I first saw this, so thank you if you are the original author. -Militis
     *
     * @param    string $var
     *
     * @return    mixed
     */
    
public function __get($var)
    {
        return 
get_instance()->$var;
    } 

Hope that helps.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

never used magic methods. 
now I know thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB