本文整理汇总了PHP中Field::getDefaultValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Field::getDefaultValue方法的具体用法?PHP Field::getDefaultValue怎么用?PHP Field::getDefaultValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Field
的用法示例。
在下文中一共展示了Field::getDefaultValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderNonSelectField
/**
* Renders a non select field.
*
* @return string (X)HTML.
*/
protected function renderNonSelectField()
{
$o = '';
if (function_exists('advfrm_custom_field_default')) {
$val = advfrm_custom_field_default($this->form, $this->field->getName(), null, isset($_POST['advfrm']));
}
if (!isset($val)) {
$val = isset($_POST[$this->name]) ? stsl($_POST[$this->name]) : $this->field->getDefaultValue();
}
if ($this->field->getType() == 'textarea') {
$cols = $this->field->getColumnCount() ? $this->field->getColumnCount() : 40;
$rows = $this->field->getRowCount() ? $this->field->getRowCount() : 4;
$o .= '<textarea id="' . $this->id . '" name="' . $this->name . '" cols="' . $cols . '" rows="' . $rows . '">' . XH_hsc($val) . '</textarea>';
} elseif ($this->field->getType() == 'output') {
$o .= $val;
} else {
if ($this->field->getType() == 'date') {
$this->initDatePicker();
}
$size = $this->field->getType() == 'hidden' || $this->field->getSize() ? ' size="' . $this->field->getSize() . '"' : '';
$maxlen = in_array($this->field->getType(), array('hidden', 'file')) || !$this->field->getMaxLength() ? '' : ' maxlength="' . $this->field->getMaxLength() . '"';
if ($this->field->getType() == 'file' && $this->field->getMaxLength()) {
$o .= tag('input type="hidden" name="MAX_FILE_SIZE" value="' . $this->field->getMaxLength() . '"');
}
if ($this->field->getType() == 'file') {
$value = '';
$accept = ' accept="' . XH_hsc($this->prefixFileExtensionList($val)) . '"';
} else {
$value = ' value="' . XH_hsc($val) . '"';
$accept = '';
}
$o .= tag('input type="' . $this->getInputElementType() . '" id="' . $this->id . '" name="' . $this->name . '"' . $value . $accept . $size . $maxlen);
}
return $o;
}
示例2: testDefaultValue
public function testDefaultValue()
{
$crud = new LouisCRUD();
$field = new Field($crud, "product_name", "varchar(255)");
$this->assertEquals(null, $field->getDefaultValue());
$field->setDefaultValue(true);
$this->assertEquals(true, $field->getDefaultValue());
$field->setDefaultValue(null);
$this->assertEquals(null, $field->getDefaultValue());
$field->setDefaultValue(1999);
$this->assertEquals(1999, $field->getDefaultValue());
$field->setDefaultValue(19.99);
$this->assertEquals(19.99, $field->getDefaultValue());
$field->setDefaultValue("1999abc");
$this->assertEquals("1999abc", $field->getDefaultValue());
$field->setDefaultValue("中文字");
$this->assertEquals("中文字", $field->getDefaultValue());
}
示例3: changeFieldToNotNullable
/**
* Change column from null to not null
* @param Field $field
*/
public function changeFieldToNotNullable($field)
{
$result = PerfORMController::getConnection()->query('select * from %n where %n is null', $field->getModel()->getTableName(), $field->getName());
$pk = $field->getModel()->getPrimaryKey();
foreach ($result as $row) {
if (!is_null($value = $field->getDefaultValue())) {
} elseif (is_callable($field->getDefaultCallback())) {
$value = call_user_func($field->getDefaultCallback(), $row);
} else {
throw new Exception("Unable to set default value for field '" . $field->getName() . "'");
}
PerfORMController::getConnection()->query('update %n set %n = %' . $field->getType() . ' where %n = %i', $field->getModel()->getTableName(), $field->getName(), $value, $pk, $row->{$pk});
}
PerfORMController::getBuilder()->changeFieldsNullable($field);
$this->updateFieldSync($field);
}