I am trying to use and understand the Entity Class in CodeIgniter 4. I am wondering how to access other (same) Entity properties within the setSomeProperty() methods if I want to enforce some business logic for one of the properties prior to say insert.
For starters I don't fully understand the concept (even outside CodeIgniter in
vanilla PHP) so I could absolutely be misunderstanding what to use Entities best for.
For an oversimplified example (that probably makes no sense):
Suppose in an Entity Class I have:
Code:
public function setSomeProperty(float $another_property) {
if (round(($this->attributes['another_property'] / 5280) * 4) < 4) {
$this->attributes['some_property'] = 4;
} else {
$this->attributes['some_property'] = round(($this->attributes['another_property'] / 5280) * 4);
}
return $this;
}
A couple of questions on this..
1. Is this the correct way to access other properties in this
set method?
2. What if I have more than one property I need to access? Does the
set method accept multiple parameters like:
Code:
setSomeProperty(float $another_property, int $another_property2)
.Thanks for help and advice.