Access public variables of class in another class both are extending CI_Controller class codeigniter php -


i want access public variables of 1 class login without extending other class check in codeigniter here variable $fb_data in class login here code of class login

class login extends ci_controller {    public $fb_data;     public function __construct()     {         parent::__construct();         $this->ci =& get_instance();         $this->load->library(array('session', 'lib_login'));         $this->load->model('users_model');         if (!isset($this->fb_data['me']) ) {           $this->fb_data = $this->lib_login->facebook();         }                      }      public function facebook()     {                        if (isset($this->fb_data['me'])) {             echo "<pre>";              var_dump($this->fb_data);             echo "</pre>";                              echo '<a href="'.site_url("login/destroy").'">logout</a>';         } else {             echo '<a href="' . $this->fb_data['loginurl'] . '">login</a>';         }     } } 

here code of class check

class check extends ci_controller {     public function __construct()     {         parent::__construct();         $this->load->library(array('session', 'lib_login'));         $this->load->model('users_model');                            }            public function index()     {                 if (isset($this->fb_data['me'])) {             echo "<pre>";              var_dump($this->fb_data);             echo "</pre>";                  echo '<a href="'.site_url("login/destroy").'">logout</a>';         } else {             echo '<a href="' . $this->fb_data['loginurl'] . '">login</a>';         }     }   } 

but whenever call check/index function gives me errore

message: undefined property: check::$fb_da 

is way can access $fb_data in advance.

first include login.php in check.php like

require_once 'login.php' 

then create isntance of login

$login = new login(); 

now access fb_data

$login->fb_data; 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -