Home >Database >Mysql Tutorial >How to Create a Doctrine Entity for a Database View in Symfony 2?
Question:
How can I create an entity class to retrieve data from a database view using Doctrine in Symfony 2? I intend to display the data but do not need any save operations.
Answer:
To establish an entity for a database view, consider the following steps:
<code class="php"><?php /** * @ORM\Entity(readOnly=true) * @ORM\Table(name="your_view_table") */ class YourEntity { private function __construct() {} }</code>
With these modifications, you can access data from the database view through the YourEntity class without the risk of inadvertent changes or object creation by other code.
The above is the detailed content of How to Create a Doctrine Entity for a Database View in Symfony 2?. For more information, please follow other related articles on the PHP Chinese website!