用symfony和doctrine进行基本读取[关闭]

I have a very basic question about getting data from a table. For example I have a table addressess and I want to get the address with address_id = ...

My mappings/models are generated with doctrine (db first). So the code is generated trough terminal.

Now I have for example an indexaction where I want to get the address with id = ...

How can I do this?

Did you read some documentation about symfony 2 and doctrine?

Documentation : http://symfony.com/doc/current/book/doctrine.html

You have to create a query using doctrine 2 (ORM) syntax.

Exemple :

$product = $this->getDoctrine()
        ->getRepository('AcmeStoreBundle:Product')
        ->find($id);

or if you want to find only one element using an id :

$repository = $this->getDoctrine()
   ->getRepository('AcmeStoreBundle:Product');
$product = $repository->findOneById($id);

If you want more complex query you can add filter to the repository :

$repository = $this->getDoctrine()
    ->getRepository('AcmeStoreBundle:Product');

$query = $repository->createQueryBuilder('p')
    ->where('p.price > :price')
    ->setParameter('price', '19.99')
    ->orderBy('p.price', 'ASC')
    ->getQuery();

$products = $query->getResult();

Look at this documentation to have more inforamtion : http://docs.doctrine-project.org/en/latest/reference/query-builder.html