I have a model extending CModel. I want to initialize this model inside protected function afterConstruct(), but that function is never run!
Also there is no constructor in any of the parent classes that initiates the afterConstructor() or onAfterConstructor() functions. So they will never run. Is this a bug?
Example code:
class MyModel extends CModel {
public $name;
// required for extending CModel
public function attributeNames() {
return array('name');
}
public function __construct() {
// Uncomment this next line, and you get an error saying "cannot call constructor":
//parent::__construct();
}
// This is never run
//public function afterConstruct() {
protected function afterConstruct() {
parent::afterConstruct();
echo "inside afterConstruct()";
}
// This is never run
public function onAfterConstruct($event) {
parent::onAfterConstruct($event);
echo "inside onAfterConstruct()";
}
}
I am running Yii 1.1.24 (last version)