gpt4 book ai didi

php - Symfony2 无法启动 session : already started by PHP

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:41:20 25 4
gpt4 key购买 nike

我遇到了一个非常奇怪的问题,看起来像这样:

[2014-11-06 11:21:13] request.INFO: Matched route "core_timetracking_new_user" (parameters: "_controller": "Bricks\Custom\CoreBundle\Controller\TimeTrackingController::newuserAction", "_route": "core_timetracking_new_user") [] []
[2014-11-06 11:21:13] request.CRITICAL: Uncaught PHP Exception RuntimeException: "Failed to start the session: already started by PHP." at /var/cache/app/prod/classes.php line 113 {"exception":"[object] (RuntimeException: Failed to start the session: already started by PHP. at /var/cache/app/prod/classes.php:113)"} []

奇怪的是我没有启动 session 或使用它,这是 Controller 代码:

/**
* @View
*/
public function newuserAction()
{
$trackingService=$this->get('core.timetracking_service');
$user= new TimeTrackingUser();
$request=$this->getRequest();

$form = $this->createFormBuilder($user)
->add('name','text')
->add('email','text')
->add('pass','password')
->add('save', 'submit', array('label' => 'Erstellen'))
->getForm();

$form->handleRequest($request);

if ($form->isValid()) {
$trackingService->persistUser($form->getData());
return $this->redirect($this->generateUrl('core_timetracking_user_list'));
}else {
return array(
'form' => $form->createView()
);
}
}

虽然这个 Action 效果很好

/**
* @View
*/
public function listuserAction()
{

$request=$this->getRequest();
$trackingService=$this->get('core.timetracking_service');
$users=$trackingService->getAllUsers();

return array(
'users' => $users
);
}

所以唯一的区别是我使用

$form->handleRequest($request); 

还检查了我的所有文件 AppKernel 等是否以

两个 Action (工作的和不工作的)都在同一个 Controller 中

最佳答案

一旦你渲染了一个表单,Symfony 就会自动启动一个 session 来存储用于 CSRF 保护的 token : http://symfony.com/doc/current/book/forms.html#csrf-protection

您可以禁用 CSRF 保护,但它默认处于启用状态。

@rakete:
我唯一的额外想法是改变 session 文件的存储方式(例如文件系统、数据库、内存等)。看这里:http://symfony.com/doc/current/components/http_foundation/session_configuration.html

关于php - Symfony2 无法启动 session : already started by PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26778786/

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