atk4\data\Model::unload PHP Method

unload() public method

Unload model.
public unload ( )
    public function unload()
    {
        $this->hook('beforeUnload');
        $this->id = null;
        $this->data = [];
        $this->dirty = [];
        $this->hook('afterUnload');
        return $this;
    }

Usage Example

Beispiel #1
0
 public function testUpdateArray()
 {
     $a = ['user' => [1 => ['name' => 'John', 'surname' => 'Smith'], 2 => ['name' => 'Sarah', 'surname' => 'Jones']]];
     $p = new Persistence_Array($a);
     $m = new Model($p, 'user');
     $m->addField('name');
     $m->addField('surname');
     $m->load(1);
     $m['name'] = 'Peter';
     $m->save();
     $m->load(2);
     $m['surname'] = 'Smith';
     $m->save();
     $m['surname'] = 'QQ';
     $m->save();
     $this->assertEquals(['user' => [1 => ['name' => 'Peter', 'surname' => 'Smith'], 2 => ['name' => 'Sarah', 'surname' => 'QQ']]], $a);
     $m->unload();
     $m->set(['name' => 'Foo', 'surname' => 'Bar']);
     $m->save();
     $this->assertEquals(['user' => [1 => ['name' => 'Peter', 'surname' => 'Smith'], 2 => ['name' => 'Sarah', 'surname' => 'QQ'], 3 => ['name' => 'Foo', 'surname' => 'Bar', 'id' => 3]]], $a);
 }
All Usage Examples Of atk4\data\Model::unload