Hi,
I am trying to load a Component (to use a shared function) in \Model\Entity\Article.php
Is there a way to load the Component in an Entity-file ?
Hi,
I am trying to load a Component (to use a shared function) in \Model\Entity\Article.php
Is there a way to load the Component in an Entity-file ?
Components are only meant to be re-used inside controllers.
If you have some custom logic which is needed inside a controller AND an entity then you will need to create a generic PHP class and call its logic via its namespace.
For completeness:
Answer to the question
You can create a componentRegistry instance without additional parameters and then create an instance of the component providing the previously created instance of the componentRegistry.
Better Way
Depending on the usecase, I would however prefer to create a php trait and use that trait in multiple places. This mechanism is used in the CakePHP source code fairly often.