public function scaffold(Model $model, $action = "", $variants = array(), $attrs = null) { $attrs = $this->parseHtmlAttrs($attrs); $result = "<form method=\"post\" action=\"{$action}\"{$attrs}><ol>"; $fields = $model->getAttributes(true); $result .= $this->hidden("id", $model->getId()); foreach ($fields as $name => $type) { if ($variants[$name] === false) { $result .= $this->hidden($name, $model->{$name}); continue; } $label = ucfirst(strtolower(str_replace("_", " ", preg_replace("/([A-Z])/", " \$1", $name)))); switch ($type) { case Model::TYPE_INTEGER: case Model::TYPE_SET: case Model::TYPE_ENUM: if (is_array($variants[$name]) || $variants[$name] instanceof Iterator || $variants[$name] instanceof IteratorAggregate) { $result .= "<li>" . $this->select($name, $variants[$name], $model->{$name}, $label) . "</li>"; } else { $result .= "<li>" . $this->input($name, $model->{$name}, $label, $variants[$name]) . "</li>"; } break; case Model::TYPE_FLOAT: $result .= "<li>" . $this->input($name, $model->{$name}, $label, $variants[$name]) . "</li>"; break; case Model::TYPE_STRING: $result .= "<li>" . $this->input($name, $model->{$name}, $label, $variants[$name], 80) . "</li>"; break; case Model::TYPE_BOOLEAN: $result .= "<li>" . $this->checkbox($name, $model->{$name}, $label) . "</li>"; break; case Model::TYPE_TIMESTAMP: $date = localtime($model->{$name}); $result .= "<li>" . $this->selectDate($name, $model->{$name}, $label, "dmyhs") . "</li>"; break; } } $result .= "<li class=\"reset\"><input type=\"reset\" value=\"Reset\" /></li>"; $result .= "<li class=\"submit\"><input type=\"submit\" value=\"Save\" /></li>"; $result .= "</ol></form>"; return $result; }
public function getAttributes() { return parent::getAttributes(); }