K
K
kapai692014-11-20 14:35:36
Doctrine ORM
kapai69, 2014-11-20 14:35:36

Doctrine 2 and Twig how to access object?

There are two entities Store and Price, you need to select the desired stores and prices for one query to the database.
The request looks very roughly like this.

$query = $this->getEntityManager()
  ->createQuery('SELECT Store, Price FROM AppStoreBundle:Store Store
    JOIN Store.prices Price
    WHERE Price.price > :price
    ORDER BY Price.price ASC');
$query->setParameter('price', 200);
$stores = $query->getResult();

It seems that everything is fine, it is selected, but in order to access the price from one store, it looks like this))
$stores[0]->getPrices()->getSnapshot()[0]->getPrice();

How can I get access to it from the template engine?
Or maybe there is a more elegant solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-11-20
Protko @Fesor

If you have such specific things, such as reports, etc. it makes sense to wrap the result in a DTO with a simple interface and pass it to the template.

K
kapai69, 2014-11-20
@kapai69

Well, it goes like this too
{{ store.prices.snapshot[0].price }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question