0

Community, i´ve got a simple COntroller for redirect my users by visiting a special path (localhost/drupal8/check). At the moment the redirect works for the administrator and for registrated user, if they are logged in, but not for the quests of my site (i know that it is only a local site).

namespace Drupal\testmodule\Controller; 
use Drupal\Core\Controller\ControllerBase;

class EntityChecker extends ControllerBase {

  public function redirectToFront($bundle, $label) { return $this->redirect('<front>');

}
}

In the log i´m getting the following error:

[30-Jul-2018 09:30:25 UTC] RuntimeException: Failed to start the session because headers have already been sent by "C:\wamp64\www\drupal8\vendor\symfony\http-foundation\Response.php" at line 1274. in C:\wamp64\www\drupal8\vendor\symfony\http-foundation\Session\Storage\NativeSessionStorage.php on line 141 #0 C:\wamp64\www\drupal8\core\lib\Drupal\Core\Session\SessionManager.php(164): Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start()

Thanks a lot for helping me

  • What does your route look like? – garethhallnz Jul 30 '18 at 10:18
  • localhost/drupal8 is the base URL and the route is localhost/drupal8/testvalue1/testvalue2 getting these parameters working fine, but not the dedirect to the front – AndyLicht Jul 31 '18 at 4:40
  • what does your *.routing.yml look like – theuni Jul 31 '18 at 14:43
0

Try this

<?php

namespace Drupal\testmodule\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\RedirectResponse;

class EntityChecker extends ControllerBase {

  public function redirectToFront($bundle, $label) {
    $response = new RedirectResponse("/");
    $response->send();
  }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.