Change Action in controller to return true or falls

I’ve made a custom buddle, and everything about that works fine, but I need to create an Action that can handle some data that I sent to it with json.

This is my Controller:

namespace Pimpilote\UploadBundle\Controller;

use Pimcore\Model\Translation\Admin;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class DefaultController extends Admin
{
    /**
     * @Route("/pimpilote_upload")
     */
    public function indexAction(Request $request)
    {
        return new Response('Hello world from pimpilote_upload');
    }

    /**
     * @Route("/default")
     */
    public function defaultAction(Request $request)
    { 
        return true;
    }
}

My routing.yml:

pimpilote_upload:
    resource: "@PimpiloteUploadBundle/Controller/"
    type:     annotation
    prefix:   /

default:
    resource: "@PimpiloteUploadBundle/Controller/"
    type:     annotation
    prefix:   /

When I call it i get that it must return a "Symfony\Component\HttpFoundation\Response" object

How can I change it so it allowed true or false?

no, a symfony request always must return a symfony response.

just return:

return $this->json(true);

Thanks for your answer @dpfaffenbauer, do I need to use a special use statement in the controller, because i get Call to undefined method json in class Pimpilote\UploadBundle\Controller\DefaultController

I was just guessing :smiley:

Try this:

use Symfony\Component\HttpFoundation\JsonResponse;
return new JsonResponse(true);

@dpfaffenbauer That worked, Thanks a lot. Next time you’re in Denmark I’ll buy you a beer :slight_smile:

@Loevbo In order to use $this->json() you’d have to extend your controller with Pimcore\Controller\FrontendController.