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

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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。