bundles/FoxHabbit/BasisBundle/Controller/DefaultController.php line 16

Open in your IDE?
  1. <?php
  2. namespace FoxHabbit\BasisBundle\Controller;
  3. use Pimcore\Controller\FrontendController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. class DefaultController extends FrontendController
  7. {
  8.     public function indexAction(Request $request)
  9.     {
  10.         return new Response('Hello world');
  11.     }
  12.     public function defaultAction(Request $request)
  13.     {
  14.         if( ! \Pimcore\Tool::isFrontendRequestByAdmin($request) && ! $this->editmode) {
  15.             $docSite \Pimcore\Tool\Frontend::getSiteForDocument ($this->document);
  16.             if( $docSite && \Pimcore\Model\Site::isSiteRequest()) {
  17.                 $site \Pimcore\Model\Site::getCurrentSite();
  18.                 if( $site->getId() != $docSite->getId()) {
  19.                     /*
  20.                         @Todo: Ist es in einem Controller nicht besser - siehe PingdomController -,
  21.                         eine Response zu erzeugen, die einem HTTP-Fehlercode entspricht und parallel
  22.                         den Fehler zu loggen? Eine Exception in einem Controller ist ja quasi nicht Catchable.
  23.                     */
  24.                     //throw new \Exception("Called from wrong site");
  25.                     // Document in site called without the correct site
  26.                     // => redirect
  27.                     $scheme $request->getScheme() . '://';
  28.                     $path   preg_replace('@^' $docSite->getRootPath() . '@''/'$this->document->getRealFullPath());
  29.                     $path preg_replace('^//''/'$path); // Remove possible double slash at the beginning
  30.                     $url    $scheme $docSite->getMainDomain() . urlencode_ignore_slash($path);
  31.                     return $this->redirect$url);
  32.                 }
  33.             } else if( $docSite) {
  34.                 // Document in site called without the correct site
  35.                 // => redirect
  36.                 $scheme $request->getScheme() . '://';
  37.                 $path   preg_replace('@^' $docSite->getRootPath() . '@''/'$this->document->getRealFullPath());
  38.                 $path preg_replace('@//@''/'$path); // Remove possible double slash at the beginning
  39.                 $url    $scheme $docSite->getMainDomain() . urlencode_ignore_slash($path);
  40.                 return $this->redirect$url);
  41.             }
  42.         }
  43.         //setlocale( LC_ALL, $this->document->getProperty('language'));
  44.         //Render the page as usual
  45.         $params = [];
  46.         if( PHP_MAJOR_VERSION 8) {
  47.             // for Pimcore < 10
  48.             $params $this->view->getAllParameters();
  49.         }
  50.         if ($template $this->document->getTemplate()) {
  51.             return $this->render($template$params);
  52.         }
  53.         return $this->render('@FoxHabbitBasis/Templates/template.html.twig'$params);
  54.     }
  55. }