Entity with Model finder (custom setters) |
I decided to get rid of dynamic properties in objects and added setters/getters
Now when the Model is executed, my new private properties are not initialized // Role private string $role; private string $title; private array $rules = []; I found the reason in generating the result: // vendor/codeigniter4/framework/system/Database/MySQLi/Result.php protected function fetchObject(string $className = 'stdClass') { if (is_subclass_of($className, Entity::class)) { return empty($data = $this->fetchAssoc()) ? false : (new $className())->setAttributes($data); } return $this->resultID->fetch_object($className); } Thus, setters are not used. How can this behavior be corrected? Overload the setAttributes() method? I found commit from iRedds https://github.com/codeigniter4/CodeIgni...35814e8dcc What was the reason for this introduction? P.S Sorry for the formatting - the post editor on the forum is broken.
Simple CI 4 project for beginners codeigniter-expenses
|
Welcome Guest, Not a member yet? Register Sign In |