Merging data into $this->data

In CakePHP, $this->data is a good place to store info. It's populated by model information when submitted by the form, it's accessible in the view, and most of the examples show model reads being pushed onto this array.

$this->data = $this->Post->read();

I've been changing things up to use array_merge instead. Any new model data will simply overwrite what is currently there and it'll prevent reads from multiple models from accidentally overwriting data in the model.

$this->data = array_merge($this->data, $this->Post->read());

If you have keys that might be the same and you want those to be merged, as well, then use array_merge_recursive.

Published August 02, 2006 · Updated August 03, 2006
Categorized as CakePHP
Short URL: http://snook.ca/s/692

Conversation

0 Comments · RSS feed
Sorry, comments are closed for this post. If you have any further questions or comments, feel free to send them to me directly.

© Jonathan Snook

Mobify empowers marketers and developers to create amazing mobile web experiences. Tap to learn more

Mobify