Since: 6.0.0 All methods except `view()` are deprecated and will be removed in the future.
Inheritance: extends eZ\Publish\Core\MVC\Symfony\Controller\Controller
 /**
  * Main action for viewing content through a location in the repository.
  * Response will be cached with HttpCache validation model (Etag)
  *
  * it is possible to change the ttl of the cache by setting a global Variable
  *
  * e.g. in twig template with a twig function which set the global variable
  *
  *  $GLOBALS['EZ_TWIG_HTTP_CACHE_TTL'] = 0; => disable cache
  *  $GLOBALS['EZ_TWIG_HTTP_CACHE_TTL'] = 3; => 3 s
  *
  * @param int $locationId
  * @param string $viewType
  * @param boolean $layout
  * @param array $params
  *
  * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  * @throws \Exception
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function viewLocation($locationId, $viewType, $layout = false, array $params = array())
 {
     // run the original ViewController from Ez
     // if all is ok we get a Response object otherwise an exception
     $response = parent::viewLocation($locationId, $viewType, $layout, $params);
     if ($response instanceof Response) {
         if (isset($GLOBALS['CJW_HTTP_CACHE_TTL'])) {
             $ttlFromTemplate = (int) $GLOBALS['CJW_HTTP_CACHE_TTL'];
             $response->setTtl($ttlFromTemplate);
             if ($ttlFromTemplate == 0) {
                 $response->setPrivate();
             }
             //echo __METHOD__ . " get http_cache ttl from tpl: $ttlFromTemplate<br>";
             //$response->headers->set( 'X-Cache-Ttl', $ttlFromTemplate );
         }
     }
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * Build the response so that depending on settings it's cacheable
  *
  * @param string|null $etag
  * @param \DateTime|null $lastModified
  *
  * @return \Symfony\Component\HttpFoundation\Response
  * @see \eZ\Publish\Core\MVC\Symfony\Controller\Content\ViewController::buildResponse
  */
 protected function buildResponse($etag = null, DateTime $lastModified = null)
 {
     if ('POST' === $this->getRequest()->getMethod()) {
         $response = new Response();
         $response->setPrivate();
         return $response;
     } else {
         return parent::buildResponse($etag, $lastModified);
     }
 }