/** * 扩展字段数据的文本框 * @author wjh 2014-5-20 * @param BFormModel $model model * @param string $attribute attribute */ public static function getExtraTextField($model, $attribute) { try { $otype = null; if ($model instanceof Product) { $otype = new ProductType(); } else { if ($model instanceof ProductForm) { $otype = new ProductType(); } else { throw new Exception('model is not null'); } } $type = $otype->findByAttributes(array('type_id' => $model->type_id)); $obj = BJSON::decodeToArray($type->struc); $extra = $obj['extra_data']; $extraStruct = ProductExtraStruct::model()->find('attributename=:attributename', array(':attributename' => $attribute)); $extraDate = ProductExtra::model()->find('attributename=:attributename and pid=:pid', array(':attributename' => $attribute, ':pid' => $model->pid)); if (!isset($extraStruct)) { echo 'not set struct ' . $attribute; die; } $value = ''; if (!is_null($extraDate)) { $value = $extraDate->vtype == 'S' ? $extraDate->attributetext : $extraDate->attributevalue; } //echo CHtml::label($extraStruct->attributelabel, $attribute); echo CHtml::textField(sprintf('ExtraForm[%s]', $attribute), $value, array('id' => sprintf('ExtraForm_%s', $attribute))); if ($extraStruct->isrequired) { echo CHtml::tag('span', array('class' => 'required'), '*'); } } catch (Exception $ex) { throw $ex; } }