selectField() public method

Return a selected field from a contentset.
public selectField ( array $content, array | string $fieldName, boolean $startempty = false, string $keyName = 'id' ) : array
$content array A Bolt record array
$fieldName array | string Name of a field, or array of field names to return from each record
$startempty boolean Whether or not the array should start with an empty element
$keyName string Name of the key in the array
return array
Beispiel #1
0
 public function testSelectFieldContentFieldArrayDerpy()
 {
     $app = $this->getApp();
     $handler = new RecordHandler($app);
     $record1 = $app['storage']->getEmptyContent('pages');
     $record2 = $app['storage']->getEmptyContent('pages');
     $record1->setValues(['title' => 'Bruce', 'slug' => 'clippy', 'status' => 'published']);
     $record2->setValues(['title' => 'Johno', 'slug' => 'koala', 'status' => 'published']);
     $result = $handler->selectField([$record1, $record2], ['title', 'derp'], true, 'slug');
     $this->assertSame('Bruce', $result['clippy'][0]);
     $this->assertNull($result['clippy'][1]);
     $this->assertSame('Johno', $result['koala'][0]);
     $this->assertNull($result['koala'][1]);
 }