Hey!
Came into another problem:
I’m writing framework-like application for my school project, and even it’s optional class I need to have the code as clean as possible.
So the situation is, I have some framework component (let’s say you’re building a game on my fw, so it may be “Unit”), that defaultly provides data from database as a standard active record. But user of this fw has to have the possibility to replace this class with his custom class, let’s say “myUnit”.
For the fw to work, I need to force having specific attributes in this class, like "attack". My standard implementation has this attribute automatcilly loaded by ActiveRecord class from database attribute, so I can read it by
$model->attack;
The problem is, I have interface "IUnit", and the way interface should work is, it should declare method "getAttack()", so I could read it by
$model->getAttack();
What is the best way to achieve that? Is it ok if I just manually write all the getters into my activerecord class, like
public function getAttack(){
return $this->attack;
}
It’s kinda sad that Yii doesn’t support those getters on db properties automatically.
I don’t have any experience with Yii so I’d be glad if someone who does would just tell me that my way is correct and that it’s not gonna cause any problems to Yii, or suggest me some better way to achieve this behaviour.
Note: I know I could just declare “getAttribute()” in the interface, but I think my teacher wouldn’t be very happy about that cause having only this in my interface doesn’t really forces custom methods to have the properties needed (like “attack”).
Thanks.