Hello,
I’m using Slim to write an API and I have followed this tutorial with TicketMapper and TicketEntity organisation :
https://www.slimframework.com/docs/tutorial/first-app.html
So, I would like to be able to access the database into a TicketEntity getter, by example :
class TicketEntity implements JsonSerializable
{
....
public function getId() {
// how to access $app->db here ?
return $this->id;
}
}
I found a way by adding an db attribute on the TicketEntity class and pass $this->db from the TicketMapper like this :
new TicketEntity($params, $this->db)
… but it seems dirty because I need to perform it everytime TicketEntity is instantiated.
Is there a better way to access the database from an entity ?
Thanks !