从Admin Class SonataAdminBundle获取存储库

时间:2017-07-27 16:44:32

标签: php symfony sonata-admin

我使用symfony 2.8和SonataAdminBundle,我想查看'客户端'这是我的代码:

ClientAdmin

public function findClient()
{   $dql = "SELECT p FROM UserBundle:User p WHERE p.type LIKE 'client' ORDER BY p.id DESC";
    return $this->getEntityManager()
        ->createQuery($dql)

        ->getResult();
}

UserRepository

  $('#map').click(function(){

   if(navigator.geolocation){

        navigator.geolocation.getCurrentPosition( display);
   }
});


function display( position){

  var div = $('#show');

  var i= position.coords.localStorage.getItem('longitude') +","+ 

  position.coords.localStorage.getItem('latitude');

  $(div).append(i);

  var imgu = "http://maps.googleapis.com/maps/api/staticmap?center="
  +i+"&zoom=15&size=400x300&sensor=false";

   $("#show").html("<img src='"+imgu+"'/>");


}

但它不起作用,仍然没有结果

1 个答案:

答案 0 :(得分:2)

您可以使用createQuery方法自定义列表查询:

    <?php

public function createQuery($context = 'list')
{
    $query = parent::createQuery($context);
    $query->andWhere(
        $query->expr()->eq($query->getRootAliases()[0] . '.my_field', ':my_param')
    );
    $query->setParameter('my_param', 'my_value');
    return $query;
}

Sonata Documentation