CodeIgniter Forums
Hot to call Superclass contructor method from subclass constructor method with parent::construct() in codeigniter custom - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Hot to call Superclass contructor method from subclass constructor method with parent::construct() in codeigniter custom (/thread-48162.html)



Hot to call Superclass contructor method from subclass constructor method with parent::construct() in codeigniter custom - El Forum - 01-06-2012

[eluser]Unknown[/eluser]
A have few games in my application, and each game have some shared functionality. For each game i created library in application/libraries/games/ directory (all files are located in that directory). One game have one file which name is the same as game name.

Here is pseudocode for 'Writeitright' game:

file Writeitright.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Writeitright extends Game {

public function __construct() {
  parent::__construct();
  echo '2. Hello from child';
}
}

file Game.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Game {
$sharedProperty; // property available in child class

public function __construct() {
  $this->sharedProperty = 1337;
  echo '1. Hello from parent<br/>';
}

protected function SharedMethod() {
  // method available in child class
}
}

in my controller file i have just:
Code:
$this->load->library('game/Writeitright');

I expected output like that:
Quote:1. Hello from parent
2. Hello from child
But i got only second line. I tried to add a prefix 'MY_' to my files and change class names to have prefix, but it does not work Sad

I think that include Game.php file into Writeitright.php should help but is that a good way to solve problem?