0

I'm trying set a varible session with an array of objects in a Symfony Controller. I had tried $session->set('expedients', serialize($expedients)); and $session->set('expedients', $expedients); too; but the next step, when I go to get the variable into a new variable in another controller, what I must do to get the original array of objects? My result by the moment is: `

object(Doctrine\ORM\PersistentCollection)#923 (9) { 
    ["snapshot":"Doctrine\ORM\PersistentCollection":private]=> array(0) { } 
    ["owner":"Doctrine\ORM\PersistentCollection":private]=> NULL 
    ["association":"Doctrine\ORM\PersistentCollection":private]=> NULL 
    ["em":"Doctrine\ORM\PersistentCollection":private]=> NULL 
    ["backRefFieldName":"Doctrine\ORM\PersistentCollection":private]=> NULL 
    ["typeClass":"Doctrine\ORM\PersistentCollection":private]=> NULL 
    ["isDirty":"Doctrine\ORM\PersistentCollection":private]=> bool(false) 
    ["collection":protected]=> object(Doctrine\Common\Collections\ArrayCollection)#925 (1) { 
    ["elements":"Doctrine\Common\Collections\ArrayCollection":private]=> array(0) { } }
    ["initialized":protected]=> bool(false)
} 
5
  • 1
    IMHO is not a good idea to store in session an PersistentCollection object. Try with a simple ArrayCollection by calling $session->set('expedients', $expedients->toArray()); Commented Dec 3, 2015 at 11:25
  • 1
    Better save some simple data (as an integer), and then (in the another controller) recovery by that integer value with a new database query, for example? Commented Dec 3, 2015 at 11:28
  • 1
    Yes @Drako more better, when you persist a doctrine object usually you lose the related object also Commented Dec 3, 2015 at 11:29
  • ->toArray() work but not quite; take your option ;-) Thanks. Commented Dec 3, 2015 at 11:33
  • Hi @Drako you are welcome, consider to post your solution as answer to your question Commented Dec 3, 2015 at 11:34

1 Answer 1

1

As @Matteo said, ->toArray(); can work (more or less) but better is save some simple data (as an integer), and then (in the another controller) recovery by that integer value with a new database query. Thanks again.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.