0
我正在製作一個移動應用程序,該應用程序必須從服務器顯示一些房屋圖像。我爲後端安裝了Symfony2,FOSRestBundle和Sonata Media Bundle。如何從音樂庫媒體包中的圖庫中獲取圖像URL,以便與FOSRestBundle一起使用?
爲了獲得房屋圖片的網址,我爲一個名爲Property的實體配置了FOSRestBundle,該實體有一個圖庫字段。這是REST控制器
class PropertiesController extends FOSRestController
{
public function getPropertiesAction()
{
$response = $this->getDoctrine()->getRepository('ComissionBundle:Property')->findAll();
if ($response == null){
return "No properties";
}
else{
return $response;
}
}
}
,但我得到這樣的:
[
{
"id":2,
"name":"test",
"city":"test",
"address":"test",
"sector":"test",
"area":0,
"rooms":112343,
"price":0,
"gallery":{
"context":"default",
"name":"test",
"enabled":false,
"updated_at":"2016-08-26T17:18:51+0200",
"created_at":"2016-08-26T17:18:51+0200",
"default_format":"default_small",
"id":1
}
}
]
正如你所看到的,有沒有媒體對象。
於是,我試着用定製的資源庫方法:
class PropertyRepository extends EntityRepository
{
public function findMainInfoElements($elements)
{
$em = $this->getEntityManager();
$queryText = "SELECT u, g, h FROM ComissionBundle:Property u JOIN u.gallery g JOIN g.galleryHasMedias h";
$query = $em->createQuery($queryText);
return $query->setMaxResults($elements)->getResult();
}
}
,但結果是一樣的。
如何從圖庫中獲取網址以便在移動應用中顯示它們? (特別是Sonata Media Bundle生成的拇指圖像,對於應用程序性能更好)