Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 4 Entity Business Logic Questions
#1

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.
Reply


Messages In This Thread
CodeIgniter 4 Entity Business Logic Questions - by josh2112o - 09-11-2021, 09:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB