[Flow] Multi step form - save values in session

Mark Kuiphuis typo3 at markyourweb.com
Sun Jun 30 05:31:39 CEST 2013


I found the problem and Alexander,...you were spot on!! logic error...

It wasn't even necessary to use putData and getData from the session 
object because as soon as you declare a model to be of scope Session, it 
works just like any model.

So, I used the code below to inject the model and this is where it went 
wrong:

/*
  * @Flow\Inject
  * @var \My\Package\Domain\Session\Model\Member
  */
protected $member;

because it should have been:

/**
  * @Flow\Inject
  * @var \My\Package\Domain\Session\Model\Member
  */
protected $member;

(hard to spot the difference, but the comment block didn't start with
/**, but instead it started with /*

What one missing asterisk won't do in a TYPO3 Flow application.

And then to think it happened to me before in an Extbase Extension I was 
developing last year :-)

Regards, Mark

On 30/06/13 10:05 AM, Mark Kuiphuis wrote:
> On 30/06/13 1:04 AM, Alexander Berl wrote:
>> Hi Mark,
>>
>> the session works by serialization/unserialization of the data, so for
>> it to work properly you need to make sure that the Object you want to
>> store can be properly serialized and unserialized, ie.
>> [igbinary_]unserialize([igbinary_]serialize($data)) == $data
>>
>> I'm not sure how it would be possible that get_class($member) returns a
>> class name but the content of $member would be an array, so maybe I'm
>> getting something wrong.
>> I would rather suspect there is some small logic error in your code
>> somewhere, for example that the session data gets overwritten with array
>> data somewhere.
>>
>> As to the propertyMapping, you are most likely just missing a proper
>> PropertyMappingConfiguration for all subproperties (assuming the
>> propertyMapper is properly injected and hence initialized and
>> is_array($session->getData('member')) is TRUE).
>>
>> Here would be a good point to provide more information in form of full
>> code of your model and the dump output after retrieval from the session
>> and (if still relevant) after the property mapping.
>>
>> Regards,
>> Alexander
>>
>> Am 29.06.2013 06:59, schrieb Mark Kuiphuis:
>>> Hi all,
>>>
>>> I am trying to get a form working which will be spread out over multiple
>>> pages. Each step will need to save the values in a session object.
>>>
>>> So I have created a model with scope session which contains all the
>>> fields amongst the 6 steps in the form.
>>>
>>> At the first "saveStep1Action()" where I create a new object of this
>>> model and assign the values from the form with setters and finally save
>>> the (partially completed) model in the session it all goes well.
>>> I don't want to put "rubbish" in the database yet, that's why I want to
>>> use the session
>>>
>>> However, after wanting to save the values from the 2nd step of the form
>>> in the same model I first need to retrieve the model from the session.
>>>
>>> So, I am using the following line of code to do that.
>>>
>>> $session = $this->sessionManager->getCurrentSession();
>>> if ($session->hasKey('member')) {
>>>     $member = $session->getData('member');
>>> }
>>>
>>> When I output this information with \TYPO3\Flow\var_dump($member) I do
>>> see the values from the 1st step in the form...so storing the session
>>> works well.
>>>
>>> echo gettype($member) shows "Object" and
>>> echo get_type($member) shows "\My\Package\Domain\Session\Model\Member"
>>> (this model does exist in this non-conventional Flow folder)
>>>
>>> I am unable to use any more setters on this model and save the newly
>>> updated model in the session again.
>>>
>>> $session->getData('member') returns an array, although get_class and
>>> gettype tell me otherwise....
>>>
>>> Because of the array being returned I have tried to use the
>>> propertyMapper to convert the session data to my model by issuing:
>>>
>>> $member = $this->propertyMapper->convert($session->getData('member'),
>>> 'My\Package\Domain\Session\Model\Member');
>>>
>>> but still it won't set the values from the second step of the form.
>>>
>>> Anyone has any ideas how to save one session model in multiple steps?
>>>
>>> Kind regards,
>>>
>>> Mark Kuiphuis
>
> Hi Alexander,
>
> I do agree 100% with your comment:
>
>  > I would rather suspect there is some small logic error in your code
>
> If I only knew what my error in logic is :-)
>
> I will do some more debugging on this the coming week, but your comment
> about serializing and unserializing the data will give me a push in the
> right direction.
>
> Thanks and will post an update if I got it to work :-)
>
> Regards,
>
> Mark



More information about the Flow mailing list