0

in the beforeSave() callback I unset a field doing:

unset($this->data['Company']['myField']);

Then, in my Company controller if I do:

debug($this->request->data) after the save()

I still see the field i unset in the model.

It seems that the change only affect the model scope and not the controller.

how can i update my $this->request->data as the data in model?

thanks

1 Answer 1

2

This is basic OOP. If you do not pass objects along (but data arrays), you cannot - by itself - expect pass by reference. Therefore modification to the data in your model cannot also alter the data in your request object. After you passed them they are independent.

If you need - for some reason - to update your request object, you need to pull the data again:

if ($this->Model->save($this->request->data)) {
    // redirect on success?
}
$this->request->data = $this->Model->data;

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.