gpt4 book ai didi

php - LogicException : The controller must return a response (null given). 您是否忘记在 Controller 中的某处添加返回语句?

转载 作者:行者123 更新时间:2023-12-04 14:41:21 26 4
gpt4 key购买 nike

注销后我想重定向到索引页面,但我在 FOSUserBundle 中收到错误

在 SecurityController.php 中

 <?php
namespace ispg\Bundle\ChatBundle\Controller;
namespace FOS\UserBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Core\Exception\AuthenticationException;

class SecurityController extends ContainerAware
{
public function loginAction()
{
$request = $this->container->get('request');
/* @var $request \Symfony\Component\HttpFoundation\Request */
$session = $request->getSession();
/* @var $session \Symfony\Component\HttpFoundation\Session */
$network = $request->get("network");

// get the error if any (works with forward and redirect -- see below)
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} elseif (null !== $session && $session->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = '';
}

if ($error) {
// TODO: this is a potential security risk (see http://trac.symfony-project.org/ticket/9523)
$error = $error->getMessage();
}

// last username entered by the user
$lastUsername = (null === $session) ? '' : $session->get(SecurityContext::LAST_USERNAME);

//create the select tag for network selection
require 'mnoNetworks.php';
$selectHtml = "<select id=\"networks\">
<option value=\"\"> -- Select -- </option>";

foreach($networks as $network){
$selectHtml .= "<option value=\"".$network."\">".$network."</option>";
}
$selectHtml .="</select>";

return $this->container->get('templating')->renderResponse('FOSUserBundle:Security:login.html.'.$this->container->getParameter('fos_user.template.engine'), array(
'last_username' => $lastUsername,
'error' => $error,
'network' => $network,
'networkSelector' => $selectHtml
));
}

public function checkAction()
{
throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
}

public function logoutAction()
{
$bundle2 = new \ispg\Bundle\ChatBundle\Controller\DefaultController();
$bundle2->setContainer($this->container);
$returned_data = $bundle2->san();
}
}

在 logoutAction session 之后我想重定向到索引页面
如何重定向到它。

谁能解决这个问题?

最佳答案

Jaitsu 是对的,只是您的 Controller 扩展了 ContainerAware 而不是为基本 Controller 操作提供快捷方式的 Controller 类...

return new Symfony\Component\HttpFoundation\RedirectResponse($this->generateUrl('name_of_route'));

关于php - LogicException : The controller must return a response (null given). 您是否忘记在 Controller 中的某处添加返回语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12576370/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com