Welcome Guest, Not a member yet? Register   Sign In
How to call a parent-class method in child class
#2

[eluser]InsiteFX[/eluser]
Code:
class MY_Controller extends CI_Controller {

protected static $name;

public function __construct() {
  parent::__construct();  
}

protected function displayName() {
  return $this->name;
}

protected function setSession($name = '') {
  $this->name = $name;
  $this->session->set_userdata('name', $name);
}

}

Code:
class Test extends MY_Controller {

public function __construct() {
  parent::__construct();
}

public function index() {
  $this->setSession('John');
  echo $this->displayName();
  var_dump($this->session->userdata('name'));
}

}

Something like that, it's up to you where you want to set the name at.


Messages In This Thread
How to call a parent-class method in child class - by El Forum - 09-20-2014, 04:27 AM
How to call a parent-class method in child class - by El Forum - 09-20-2014, 05:06 AM
How to call a parent-class method in child class - by El Forum - 09-20-2014, 07:13 AM
How to call a parent-class method in child class - by El Forum - 09-20-2014, 12:35 PM
How to call a parent-class method in child class - by El Forum - 09-20-2014, 04:05 PM
How to call a parent-class method in child class - by El Forum - 09-20-2014, 07:30 PM



Theme © iAndrew 2016 - Forum software by © MyBB