Skip to content

Instantly share code, notes, and snippets.

@acrosman
Created May 6, 2017 18:52
Show Gist options
  • Save acrosman/945d29162d3ba0e0101333638dd88295 to your computer and use it in GitHub Desktop.
Save acrosman/945d29162d3ba0e0101333638dd88295 to your computer and use it in GitHub Desktop.
A simple example Drupal Controller with an uncached JsonResponse
<?php
namespace Drupal\example\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
class ExampleController extends ControllerBase {
public function getJson(Request $request) {
$data = [];
// Do some useful stuff to build an array of data.
return new JsonResponse($data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment