atk4\data\Model::export PHP Method

export() public method

Export DataSet as array of hashes.
public export ( array | null $fields = null ) : array
$fields array | null
return array
    public function export($fields = null)
    {
        return $this->persistence->export($this, $fields);
    }

Usage Example

Example #1
0
 public function testType()
 {
     $a = ['types' => [['string' => 'foo', 'date' => '2013-02-20', 'datetime' => '2013-02-20 20:00:12', 'time' => '12:00:50', 'boolean' => '1', 'integer' => '2940', 'money' => '8.20', 'float' => '8.202343', 'array' => '[1,2,3]']]];
     $this->setDB($a);
     date_default_timezone_set('Asia/Seoul');
     $db = new Persistence_SQL($this->db->connection);
     $m = new Model($db, ['table' => 'types']);
     $m->addField('string', ['type' => 'string']);
     $m->addField('date', ['type' => 'date']);
     $m->addField('datetime', ['type' => 'datetime']);
     $m->addField('time', ['type' => 'time']);
     $m->addField('boolean', ['type' => 'boolean']);
     $m->addField('money', ['type' => 'money']);
     $m->addField('float', ['type' => 'float']);
     $m->addField('integer', ['type' => 'integer']);
     $m->addField('array', ['type' => 'array']);
     $m->load(1);
     $this->assertSame('foo', $m['string']);
     $this->assertSame(true, $m['boolean']);
     $this->assertSame(8.199999999999999, $m['money']);
     $this->assertEquals(new \DateTime('2013-02-20'), $m['date']);
     $this->assertEquals(new \DateTime('2013-02-21 05:00:12'), $m['datetime']);
     $this->assertEquals(new \DateTime('12:00:50'), $m['time']);
     $this->assertSame(2940, $m['integer']);
     $this->assertEquals([1, 2, 3], $m['array']);
     $this->assertSame(8.202343000000001, $m['float']);
     $m->duplicate()->save();
     $a = ['types' => [1 => ['id' => '1', 'string' => 'foo', 'date' => '2013-02-20', 'datetime' => '2013-02-20 20:00:12', 'time' => '12:00:50', 'boolean' => 1, 'integer' => 2940, 'money' => 8.199999999999999, 'float' => 8.202343000000001, 'array' => '[1,2,3]'], 2 => ['id' => '2', 'string' => 'foo', 'date' => '2013-02-20', 'datetime' => '2013-02-20 20:00:12', 'time' => '12:00:50', 'boolean' => '1', 'integer' => '2940', 'money' => '8.2', 'float' => '8.202343', 'array' => '[1,2,3]']]];
     $this->assertEquals($a, $this->getDB());
     list($first, $duplicate) = $m->export();
     unset($first['id']);
     unset($duplicate['id']);
     $this->assertEquals($first, $duplicate);
 }
All Usage Examples Of atk4\data\Model::export