Extends
lithium\data\Entity
Allows several properties to be assigned at once.
For example:
{{{
$doc->set(array('title' => 'Lorem Ipsum', 'value' => 42));
}}}
Parameters
- array $data An associative array of fields and values to assign to the `Document`.
- array $options
Returns
voidSource
public function set(array $data, array $options = array()) {
$defaults = array('init' => false);
$options += $defaults;
foreach ($data as $key => $val) {
if (strpos($key, '.')) {
$this->_setNested($key, $val);
unset($data[$key]);
}
unset($this->_increment[$key]);
}
if ($data && $model = $this->_model) {
$pathKey = $this->_pathKey;
$data = $model::connection()->cast($this, $data, compact('pathKey'));
}
foreach ($data as $key => $value) {
if ($value instanceof self) {
if (!$options['init']) {
$value->_exists = false;
}
$value->_pathKey = ($this->_pathKey ? "{$this->_pathKey}." : '') . $key;
$value->_model = $value->_model ?: $this->_model;
$value->_schema = $value->_schema ?: $this->_schema;
}
}
$this->_updated = $data + $this->_updated;
}