douqiang1910 2013-07-17 12:03
浏览 67
已采纳

ErrorException:警告:标题可能不包含多个标题,检测到新行

I am having trouble redirecting after a certain function that sends emails! My function is:

public function emailAction($emails, $url)
{

    foreach($emails as $email)
    {
        $message = \Swift_Message::newInstance()
            ->setSubject('Updates in Symfony Blog')
            ->setFrom(array('blog@symfonyblog.com' => 'Symfony Blog'))
            ->setTo($email["email"])
            ->setBody(
            $this->renderView(
                'NEWSBlogBundle:Default:email.txt.twig',
                array('url' => $url)
            )
        )
        ;
        $this->get('mailer')->send($message);
    }

    return $this->redirect($this->newpostAction());
    //return $this->redirect($this->generateUrl('NEWSBlogBundle_homepage'));

}

It sends the emails OK, but then when redirecting, gives the error:

ErrorException: Warning: Header may not contain more than a single header, new line detected in C:\path\to\webroot\Symfony\app\cache\dev\classes.php line 3899

  1. in C:\path\to\webroot\Symfony\app\cache\dev\classes.php line 3899
  2. at ErrorHandler->handle('2', 'Header may not contain more than a single header, new line detected', 'C:\path\to\webroot\Symfony\app\cache\dev\classes.php', '3899', array('this' => object(RedirectResponse), 'name' => 'Location', 'values' => array('/app_dev.php/blog', object(ResponseHeaderBag), ' Redirecting to /app_dev.php/blog Redirecting to /app_dev.php/blog. ', '1.0', '302', 'Found', null), 'value' => object(ResponseHeaderBag)))
  3. at header('Location: Cache-Control: no-cache Date: Wed, 17 Jul 2013 11:56:17 GMT Location: /app_dev.php/blog ', false) in C:\path\to\webroot\Symfony\app\cache\dev\classes.php line 3899
  4. at Response->sendHeaders() in C:\path\to\webroot\Symfony\app\cache\dev\classes.php line 3914
  5. at Response->send() in C:\path\to\webroot\Symfony\web\app_dev.php line 27

while I haven't changed anything about any "headers" (and don't really know what it is about!). My app_dev.php is:

<?php

use Symfony\Component\HttpFoundation\Request;

if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

I tried two different ways of redirecting both (through routing and directly calling the controller) of which give the same error, whilst the pages load if I jusr type in their url!

I have NO idea what this error is and how I should fix it!

  • 写回答

2条回答 默认 最新

  • duanchu0031 2013-07-18 12:27
    关注

    To be detail, your problem was the return value of $this->newpostAction(). Usally it's a Response object. But a redirect expects an uri/route, which can be sent to the client via the Location header. A redirect is always a client side turn around. But you can use ->forward('AcmeBundle:Demo:index') to forward internally to another controller action. In this case the URL on the client is not changed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?