Monday, September 29, 2008

Re: Form wizard component save data

I wasn't clear enough. It does not loose the data. It just won't
provide the controller with the data since it expects each step to be
totally isolated from previous ones. The session-storage is really
only designed to populate the form-fields of each step should you wish
choose to go backwards. It was not meant to give you access to it for
a final "save" at the end of the wizard.

I find it a bit strange but looking at the source it is clear this is
a design decision and not a bug. If you want to have access to the
full data at the end of the wizard (without hacking into the session
data from the controller) you must modify the component or suggest
changes to the original developer.

in short: controller::data is populated from a session key for the
current step not a "common" key e.g. "Wizard.step1" not
"Wizard.data".
What I did was to make the wizard also:
• merge "new" data and "old" session-data and save that separately
(in a common session-key)
• return this combined data to the controller on each request.

A small mod is not difficult and if your changes do not break anything
else you can suggest an improvement and provide an implementation.
For what you need (as I understand it) you could look for
afterComplete in the source and set the controllers "data" property
with all the data before executing that method.

Like this for example:
find:
if(method_exists($this->Controller,'afterComplete')) {
$this->Controller->afterComplete();
}

replace with:
if(method_exists($this->Controller,'afterComplete')) {
foreach ( $this->setps as $a_step ) {
$this->Controller->data = array_merge_recursive($this->Session-
>read("$this->sessionKey.$a_step"),$this->Controller->data);
}
$this->Controller->afterComplete();
}

in the method afterComplete() you would then have a $this->data
containing the data from all steps.


/Martin

On Sep 29, 4:01 pm, mcphisto <mcphisto1...@gmail.com> wrote:
> I find it strange that this wizard looses its varibales/data during
> the steps. If it would be like this, you shouldn't see data when you
> go back to a previous step. You shuold loose everything. If you move
> your debug value to 3, you're able to see data in your session. So I
> could see that in third step, I've data of the first step, the only
> problem is that if I use a normal save->data, it doesn't work. Is
> there anyone else who had the same problem as me and Martin?
>
> On 29 Set, 14:27, "martin.westin...@gmail.com"
>
> <martin.westin...@gmail.com> wrote:
> > I just noticed that the component restes the wizard before sending you
> > to the receipt. How I am supposed to show a receipt for a transaction
> > I no linger have access to, I don't know.
>
> > There is apparently also an afterComplete() action that the component
> > looks for just before resetting. I guess that is our last chance to
> > save out data in a session variable of out ow or something similar.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: