/** * Add a model's rendered elements to this form. * * All models must have a common prefix, generally this is "model", but if multiple models are on one form, * then different prefixes can be used. * * @param Model $model The model to populate elements from * @param string $prefix The prefix to create elements as */ public function addModel(Model $model, $prefix = 'model'){ // Is this model already attached? if(isset($this->_models[$prefix])){ return; } $this->_models[$prefix] = $model; $s = $model->getKeySchemas(); $i = $model->GetIndexes(); if (!isset($i['primary'])){ $i['primary'] = array(); } foreach ($s as $k => $v) { $el = $model->getColumn($k)->getAsFormElement(); if($el !== null){ // Update the name as it will need to be prefixed with this model's prefix. $el->set('name', $prefix . '[' . $k . ']'); // I need to give the model a chance to act on this new element too. // Sometimes models may have a few special things to update on the element. // $model->setFromForm($this, $prefix); $model->setToFormElement($k, $el); $this->addElement($el); } } // Anything else? $model->addToFormPost($this, $prefix); }