Let's say I have a view table. And I want to get data from it to an entity. Can I (and how) create entity class to do that (no save operation needed)? I just want to display them.
Symfony provides all the tools you need to use databases in your applications thanks to Doctrine, the best set of PHP libraries to work with databases. These tools support relational databases like MySQL and PostgreSQL and also NoSQL databases like MongoDB.
An entity is an object that represent the underlying data (as @perovic said: exactly one line of data from a single table, joined with data from other tables).
The Doctrine Project is the home to several PHP libraries primarily focused on database storage and object mapping. The core projects are the Object Relational Mapper (ORM) and the Database Abstraction Layer (DBAL) it is built upon.
The EntityManager is the central access point to ORM functionality. It can be used to find, persist, flush and remove entities.
The accepted answer is correct, but I'd like to offer some additional suggestions that you might want to consider:
Mark your entity as read-only.
Make the constructor private so that only Doctrine can create instances.
/** * @ORM\Entity(readOnly=true) * @ORM\Table(name="your_view_table") */ class YourEntity { private function __construct() {} }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With