Search code examples
phpmysqlsymfonydoctrine-orm

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.


Solution

  • There is nothing special in querying a view — it's just a virtual table. Set the table of your entity this way and enjoy:

    /**
     * @ORM\Entity
     * @ORM\Table(name="your_view_table")
     */
    class YourEntity {
        // ...
    }