lithium\data\entity\Document::set PHP Метод

set() публичный Метод

For example: $doc->set(array('title' => 'Lorem Ipsum', 'value' => 42));
public set ( array $data, array $options = [] ) : void
$data array An associative array of fields and values to assign to the `Document`.
$options array
Результат void
    public function set(array $data, array $options = array())
    {
        $defaults = array('init' => false);
        $options += $defaults;
        $cast = $schema = $this->schema();
        foreach ($data as $key => $val) {
            unset($this->_increment[$key]);
            if (strpos($key, '.')) {
                $this->_setNested($key, $val);
                continue;
            }
            if ($cast) {
                $pathKey = $this->_pathKey;
                $model = $this->_model;
                $parent = $this;
                $val = $schema->cast($this, $key, $val, compact('pathKey', 'model', 'parent'));
            }
            if ($val instanceof self) {
                $val->_exists = $options['init'] && $this->_exists;
                $val->_pathKey = ($this->_pathKey ? "{$this->_pathKey}." : '') . $key;
                $val->_model = $val->_model ?: $this->_model;
                $val->_schema = $val->_schema ?: $this->_schema;
            }
            $this->_updated[$key] = $val;
        }
    }

Usage Example

Пример #1
0
 public function testBooleanValues()
 {
     $doc = new Document(array('model' => $this->_model));
     $doc->tall = false;
     $doc->fat = true;
     $doc->set(array('hair' => true, 'fast' => false));
     $expected = array('tall', 'fat', 'hair', 'fast');
     $this->assertEqual($expected, array_keys($doc->data()));
 }
All Usage Examples Of lithium\data\entity\Document::set