Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 Failed to start the session: already started by PHP

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)"} []

the strange thing is i do not start a session or use it, heres the Controller code:

/**
 * @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()
        );
    }
}

while this action works wonderfull

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

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

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

so the only difference is that i use

$form->handleRequest($request); 

also checked if all my files AppKernel etc do start with

both actions ( the working one and the not working one ) are in the same controller

like image 409
john Smith Avatar asked Sep 30 '22 11:09

john Smith


1 Answers

As soon as you render a form, Symfony automatically starts a session to store the token for CSRF Protection: http://symfony.com/doc/current/book/forms.html#csrf-protection

You can disable CSRF Protection, but it's on by default.

@rakete:
The only additional idea I have is to change the way in which session files are stored (e.g. file system, database, memory, etc.). See here: http://symfony.com/doc/current/components/http_foundation/session_configuration.html

like image 110
Thomas Landauer Avatar answered Oct 02 '22 14:10

Thomas Landauer