Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up entity (doctrine) for database view in Symfony 2

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.

like image 254
user1063963 Avatar asked Dec 04 '11 18:12

user1063963


People also ask

Does Symfony use doctrine?

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.

What is an entity in Symfony?

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).

What is doctrine database?

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.

What is Entity Manager in doctrine?

The EntityManager is the central access point to ORM functionality. It can be used to find, persist, flush and remove entities.


1 Answers

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() {} } 
like image 75
Ian Phillips Avatar answered Oct 02 '22 21:10

Ian Phillips