【发布时间】:2013-07-17 12:03:46
【问题描述】:
在某个发送电子邮件的功能之后,我无法重定向! 我的功能是:
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'));
}
它可以发送电子邮件,但是在重定向时,会出现错误:
ErrorException: 警告:标头可能不包含多个标头,在 C:\path\to\webroot\Symfony\app\cache\dev\classes.php 第 3899 行中检测到新行
- 在 C:\path\to\webroot\Symfony\app\cache\dev\classes.php 第 3899 行
- 在 ErrorHandler->handle('2', '标头不能包含多个标头,检测到新行', '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), ' 重定向to /app_dev.php/blog 重定向到/app_dev.php/blog.', '1.0', '302', 'Found', null), 'value' => object(ResponseHeaderBag)))
- 在标头('位置:缓存控制:无缓存日期:星期三,2013 年 7 月 17 日 11:56:17 GMT 位置:/app_dev.php/blog ',假)在 C:\path\to\webroot \Symfony\app\cache\dev\classes.php 第 3899 行
- 在 Response->sendHeaders() 在 C:\path\to\webroot\Symfony\app\cache\dev\classes.php 第 3914 行
- 在 C:\path\to\webroot\Symfony\web\app_dev.php 第 27 行中的 Response->send() 处
虽然我没有更改任何有关“标题”的任何内容(而且我真的不知道它是关于什么的!)。我的 app_dev.php 是:
<?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);
我尝试了两种不同的重定向方式(通过路由和直接调用控制器),它们给出了相同的错误,而如果我输入他们的 url,页面就会加载!
我不知道这个错误是什么以及我应该如何解决它!
【问题讨论】:
-
也许您的文件中某处有空格输出
-
$this->newpostAction()的返回值是多少 -
@Pazi 这是一个加载页面的控制器函数。
-
我没有弄清楚问题出在哪里,但我删除了“函数”并将其功能添加到调用它的控制器中,我的问题就解决了!