metadata = $metadata; } $this->sharedData['metadata'] = array( 'primaryKey' => null, 'columns' => array() ); } public function postInitialize() { if ($this->metadata == null) { $this->metadata = new Metadata($this->tableGateway->adapter); } // localize variable for brevity $t = $this->tableGateway; $m = $this->metadata; // get column named $columns = $m->getColumnNames($t->table); $t->columns = $columns; // set locally $this->sharedData['metadata']['columns'] = $columns; // process primary key only if table is a table; there are no PK constraints on views if (!($m->getTable($t->table) instanceof TableObject)) { return; } $pkc = null; foreach ($m->getConstraints($t->table) as $constraint) { /** @var $constraint \Zend\Db\Metadata\Object\ConstraintObject */ if ($constraint->getType() == 'PRIMARY KEY') { $pkc = $constraint; break; } } if ($pkc === null) { throw new Exception\RuntimeException('A primary key for this column could not be found in the metadata.'); } if (count($pkc->getColumns()) == 1) { $pkck = $pkc->getColumns(); $primaryKey = $pkck[0]; } else { $primaryKey = $pkc->getColumns(); } $this->sharedData['metadata']['primaryKey'] = $primaryKey; } }