i got a very strange issue looking like this:
[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)"} []
奇怪的是,我并没有开始一个会话或使用它。以下是控制器代码:
/**
* @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()
);
}
}
虽然这个操作非常有效,但是需要注意:
/**
* @View
*/
public function listuserAction()
{
$request=$this->getRequest();
$trackingService=$this->get('core.timetracking_service');
$users=$trackingService->getAllUsers();
return array(
'users' => $users
);
}
所以唯一的区别是我使用了。
$form->handleRequest($request);
我检查了所有文件(包括AppKernel等)是否以正确的格式开始。
这两个操作(一个正常,一个异常)都在同一个控制器中。