本文整理汇总了PHP中TextField::setAsNumeric方法的典型用法代码示例。如果您正苦于以下问题:PHP TextField::setAsNumeric方法的具体用法?PHP TextField::setAsNumeric怎么用?PHP TextField::setAsNumeric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextField
的用法示例。
在下文中一共展示了TextField::setAsNumeric方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getForm
/**
* Returns the form that this controller uses to manipulate the data stored
* in its model. As stated earlier the form is either automatically generated
* or it is loaded from an existing file which is located in the same
* directory as the model and bears the model's name.
*
* @return Form
*/
protected function getForm()
{
// Load a local form if it exists.
if ($this->redirected) {
$formName = $this->redirectedPackageName . Application::camelize($this->mainRedirectedPackage) . "Form";
$formPath = $this->redirectPath . "/" . str_replace(".", "/", $this->mainRedirectedPackage) . "/" . $formName . ".php";
} else {
$formName = Application::camelize($this->model->package) . "Form";
$formPath = $this->localPath . "/" . $formName . ".php";
}
if (is_file($formPath)) {
include_once $formPath;
$form = new $formName();
} else {
if (is_file($this->localPath . "/" . $this->name . "Form.php")) {
include_once $this->localPath . "/" . $this->name . "Form.php";
$formclass = $this->name . "Form";
$form = new $formclass();
$form->setModel($this->model);
} else {
// Generate a form automatically
$fieldNames = array();
$fields = $this->model->getFields();
$form = new Form();
$form->setModel($this->model);
$names = array_keys($fields);
for ($i = 0; $i < count($fields); $i++) {
$field = $fields[$names[$i]];
if ($field['key'] == 'primary') {
continue;
}
if ($fieldNames[$i]["renderer"] == "") {
if ($field["reference"] == "") {
switch ($field["type"]) {
case "boolean":
$element = new Checkbox($field["label"], $field["name"], $field["description"], 1);
break;
case "enum":
$element = new SelectionList($field["label"], $field["name"]);
foreach ($field["options"] as $value => $option) {
$element->addOption($option, $value . "");
}
break;
case "date":
case "datetime":
$element = new DateField($field["label"], $field["name"]);
break;
case "integer":
case "double":
$element = new TextField($field["label"], $field["name"], $field["description"]);
$element->setAsNumeric();
break;
case "textarea":
$element = new TextArea($field["label"], $field["name"], $field["description"]);
break;
default:
$element = new TextField($field["label"], $field["name"], $field["description"]);
break;
}
} else {
$element = new ModelField($field["reference"], $field["referenceValue"]);
}
foreach ($field["validators"] as $validator) {
switch ($validator["type"]) {
case "required":
$element->setRequired(true);
break;
case "unique":
$element->setUnique(true);
break;
case "regexp":
$element->setRegexp((string) $validator["parameter"]);
break;
}
}
} else {
$renderer = (string) $fieldNames[$i]["renderer"];
$element = new $renderer();
}
$form->add($element);
}
$form->addAttribute("style", "width:50%");
$form->useAjax(true, false);
}
}
return $form;
}
示例2: createDefaultForm
private function createDefaultForm()
{
// Generate a form automatically
$fieldNames = array();
$fields = $this->model->getFields();
$form = new Form();
$names = array_keys($fields);
for ($i = 0; $i < count($fields); $i++) {
$field = $fields[$names[$i]];
if ($field['key'] == 'primary') {
continue;
}
if ($fieldNames[$i]["renderer"] == "") {
if ($field["reference"] == "") {
switch ($field["type"]) {
case "boolean":
$element = new Checkbox($field["label"], $field["name"], $field["description"], 1);
break;
case "enum":
$element = new SelectionList($field["label"], $field["name"]);
foreach ($field["options"] as $value => $option) {
$element->addOption($option, $value . "");
}
break;
case "date":
case "datetime":
$element = new DateField($field["label"], $field["name"]);
break;
case "integer":
case "double":
$element = new TextField($field["label"], $field["name"], $field["description"]);
$element->setAsNumeric();
break;
case "textarea":
$element = new TextArea($field["label"], $field["name"], $field["description"]);
break;
default:
$element = new TextField($field["label"], $field["name"], $field["description"]);
break;
}
} else {
$element = new ModelField($field["reference"], $field["referenceValue"]);
}
foreach ($field["validators"] as $validator) {
switch ($validator["type"]) {
case "required":
$element->setRequired(true);
break;
case "unique":
$element->setUnique(true);
break;
case "regexp":
$element->setRegexp((string) $validator["parameter"]);
break;
}
}
} else {
$renderer = (string) $fieldNames[$i]["renderer"];
$element = new $renderer();
}
$form->add($element);
}
$form->addAttribute("style", "width:50%");
$form->useAjax(true, false);
return $form;
}