DataCaster not working |
Hi. There is an error when converting DataСaster types for an Entity, the set() method is not specified. Because of this, type casting does not work.
Look at this https://github.com/codeigniter4/CodeIgni...st.php#L24 My code Entity: PHP Code: // Step 1, fill properties But some Casts (IntegerCast, FloatCast, ...) don't have a set (only get) method and everything breaks
Simple CI 4 project for beginners codeigniter-expenses
You can't use DataCaster\Cast classes with Entity Property casting.
It is a misuse. You must use Entity\Cast classes. DataCaster\Cast classes are for Model Field casting. https://codeigniter4.github.io/CodeIgnit...ld-casting
This happens in the Model. I get the data in the form of an entity.
PHP Code: final class SettingsParameter extends Entity For getId() I can't get ?int So I need to move the $cast parameter to the Model? Can this affect the entity in the future?
Simple CI 4 project for beginners codeigniter-expenses
The SettingsParameter entity does not work, because you added private properties.
Remove all the private properties if you want to use Entity.
Everything is working well. I change $attributes myself and use setXXX() to set the properties. The only problem is with typing. Before that, everything worked because there were no strict_types=1 in the system files.
I tried to put $casts into the Model and it works
Simple CI 4 project for beginners codeigniter-expenses
Entity Property casting and Using Model Field casting with Entity behaves differently.
See Important note in https://codeigniter4.github.io/CodeIgnit...ld-casting |
Welcome Guest, Not a member yet? Register Sign In |