atk4\data\Model::loadAny PHP Méthode

loadAny() public méthode

Load any record.
public loadAny ( )
    public function loadAny()
    {
        if (!$this->persistence) {
            throw new Exception(['Model is not associated with any database']);
        }
        if ($this->loaded()) {
            $this->unload();
        }
        $this->data = $this->persistence->loadAny($this);
        if ($this->data) {
            $this->id = $this->data[$this->id_field];
            $this->hook('afterLoad');
        } else {
            $this->unload();
        }
        return $this;
    }

Usage Example

Exemple #1
0
 public function testTimestampSave()
 {
     $a = ['types' => [['date' => '']]];
     $this->setDB($a);
     $db = new Persistence_SQL($this->db->connection);
     $m = new Model($db, ['table' => 'types']);
     $m->addField('ts', ['actual' => 'date', 'type' => 'date']);
     $m->loadAny();
     $m['ts'] = new \DateTime('2012-02-30');
     $m->save();
     // stores valid date.
     $this->assertEquals(['types' => [1 => ['id' => 1, 'date' => '2012-03-01']]], $this->getDB());
 }
All Usage Examples Of atk4\data\Model::loadAny