本文整理汇总了PHP中GridField::getCastedValue方法的典型用法代码示例。如果您正苦于以下问题:PHP GridField::getCastedValue方法的具体用法?PHP GridField::getCastedValue怎么用?PHP GridField::getCastedValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GridField
的用法示例。
在下文中一共展示了GridField::getCastedValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: castValue
/**
* Casts a field to a string which is safe to insert into HTML
*
* @param GridField $gridField GridField to cast value for
* @param string $fieldName Field name to cast value for
* @param string $value Value to cast
*
* @return string
*
* @author Sebastian Diel <sdiel@pixeltricks.de>
* @since 26.03.2013
*/
protected function castValue($gridField, $fieldName, $value)
{
// If a fieldCasting is specified, we assume the result is safe
if (array_key_exists($fieldName, $this->fieldCasting)) {
$value = $gridField->getCastedValue($value, $this->fieldCasting[$fieldName]);
} else {
if (is_object($value)) {
// If the value is an object, we do one of two things
if (method_exists($value, 'Nice')) {
// If it has a "Nice" method, call that & make sure the result is safe
$value = Convert::raw2xml($value->Nice());
} else {
// Otherwise call forTemplate - the result of this should already be safe
$value = $value->forTemplate();
}
} elseif (!$this->isHtmlAllowedFor($fieldName, $gridField)) {
// Otherwise, just treat as a text string & make sure the result is safe
$value = Convert::raw2xml($value);
}
}
return $value;
}
示例2: testGetCastedValueObject
/**
* @covers GridField::getCastedValue
*/
public function testGetCastedValueObject()
{
$obj = new GridField('testfield', 'testfield');
$value = $obj->getCastedValue('This is a sentance. This ia another.', 'Date');
$this->assertEquals(null, $value);
}
示例3: castValue
/**
*
* @param GridField $gridField
* @param string $fieldName
* @param string $value
* @return string
*/
protected function castValue($gridField, $fieldName, $value)
{
if (array_key_exists($fieldName, $this->fieldCasting)) {
return $gridField->getCastedValue($value, $this->fieldCasting[$fieldName]);
} elseif (is_object($value) && method_exists($value, 'Nice')) {
return $value->Nice();
}
return $value;
}