コード例 #1
0
ファイル: myForm.php プロジェクト: huoybb/standard
 public static function buildFormFromModel(\Phalcon\Mvc\Model $model, array $extraFields = null)
 {
     if ($model->id) {
         $form = new Form($model);
     } else {
         $form = new Form();
     }
     $fields = [];
     foreach ($model->columnMap() as $column) {
         $metaDataTypes = $model->getModelsMetaData()->getDataTypes($model);
         if (!in_array($column, ['created_at', 'updated_at', 'id', 'password', 'remember_token'])) {
             if ($metaDataTypes[$column] != 6) {
                 $form->add(new Text($column));
             } else {
                 $form->add(new TextArea($column));
             }
             $fields[] = $column;
         }
     }
     if (null != $extraFields) {
         foreach ($extraFields as $column) {
             if (in_array($column, $model->columnMap())) {
                 continue;
             }
             $form->add(new Text($column));
             $fields[] = $column;
         }
     }
     $form->fields = $fields;
     if ($model->id) {
         $form->add(new Submit('修改'));
     } else {
         $form->add(new Submit('增加'));
     }
     return $form;
 }