public static function buildFormFromModel(myModel $object) { $form = new Form($object); $fields = []; foreach ($object->columnMap() as $column) { if (!in_array($column, ['created_at', 'updated_at', 'id'])) { $form->add(new \Phalcon\Forms\Element\Text($column)); $fields[] = $column; } } $form->fields = $fields; $form->add(new \Phalcon\Forms\Element\Submit('修改')); return $form; }
protected function buildFormFromModel(myModel $model) { if ($model->id) { $form = new Form($model); } else { $form = new Form(); } $fields = []; foreach ($model->columnMap() as $column) { if (!in_array($column, ['created_at', 'updated_at', 'id', 'password', 'remember_token'])) { $form->add(new \Phalcon\Forms\Element\Text($column)); $fields[] = $column; } } $form->fields = $fields; if ($model->id) { $form->add(new \Phalcon\Forms\Element\Submit('修改')); } else { $form->add(new \Phalcon\Forms\Element\Submit('增加')); } return $form; }