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

前端 未结 6 1369
心在旅途
心在旅途 2020-11-30 01:51

Lets 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

6条回答
  •  长情又很酷
    2020-11-30 02:29

    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() {}
    }
    

提交回复
热议问题