<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webignition / simplytestable-pagecache-bundle example snippets
namespace App\Controller;
use SimplyTestable\PageCacheBundle\Services\CacheableResponseFactory;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig_Environment;
class ExampleController
{
public function exampleAction(
CacheableResponseFactory $cacheableResponseFactory,
Twig_Environment $twig,
Request $request
): Response {
// ... perform whatever operation your action oesn't match what
// the request is asking for. Render and return a response based on the response
// already created
$response->setContent($twig->render(
'::base.html.twig',
[]
));
return $response;
}
}
namespace App\Controller;
use App\Entity\Post;
use Doctrine\ORM\EntityManagerInterface;
use SimplyTestable\PageCacheBundle\Services\CacheableResponseFactory;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig_Environment;
class ExampleController
{
public function exampleAction(
$post_id,
EntityManagerInterface $entityManager,
CacheableResponseFactory $cacheableResponseFactory,
Twig_Environment $twig,
Request $request
): Response {
$postRepository = $entityManager->getRepository(Post::class);
$post = $postRepository->find($post_id);
$response = CacheableResponseFactory->createResponse($request, [
'post_id' => $post_id,
]);
if (Response::HTTP_NOT_MODIFIED === $response->getStatusCode()) {
return $response;
}
$response->setContent($twig->render(
'post.html.twig',
[
'post' => $post,
]
));
return $response;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.