i try to view some rows from a table. I have one AjaxController in Symfony, this controller have the following function:
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
use Rowoco\AllgemeinBundle\Entity\Place;
use Symfony\Component\HttpFoundation\JsonResponse;
.
.
.
public function defaultAjaxAction( $job )
{
$user = $this->get('security.context')->getToken()->getUser();
$userId = $user->getId();
$result = $this->$job( $userId );
// Initialisiert Serializer
$encoder = [new JsonEncoder()];
$normalizer = [new GetSetMethodNormalizer()];
$serializer = new Serializer($normalizer, $encoder);
$newData = $serializer->serialize($result, 'json');
return new Response($newData);
}
public function getPlacelist( $iduser )
{
$em = $this->getDoctrine()->getManager();
$request = Request::createFromGlobals();
//if i put here a return 123, then the output in the javascript-console would return 123
$placeRepo = $em->getRepository( "RowocoAllgemeinBundle:Place" );
$placeEntity = $placeRepo->findBy(
array(),
array(),
$request->request->get( "limitCount" ),
$request->request->get( "limitStart" )
);
return new JsonResponse(array('place' => $placeEntity));
}
In my js-file i call it with this function:
function getPlaces()
{
var data = {};
data['limitCount'] = 10;
data['limitStart'] = 0;
var url = $( "#pageparameter" ).data( "url-getplacelist" );
$.ajax({
type: "POST",
url: url,
data: data,
dataType: "json"
})
.done(function(resp){
console.log(resp);
$( "#viewPlaces").html(resp.place.description);
})
.error(function(){
console.log("No connection");
});
}
In the table, i have 2 rows and see them in the workbench.
I dont use a repository. I only using the basic functions from symfony.