本文整理汇总了PHP中DbHelper::getTextualColumnTypeByContentLength方法的典型用法代码示例。如果您正苦于以下问题:PHP DbHelper::getTextualColumnTypeByContentLength方法的具体用法?PHP DbHelper::getTextualColumnTypeByContentLength怎么用?PHP DbHelper::getTextualColumnTypeByContentLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbHelper
的用法示例。
在下文中一共展示了DbHelper::getTextualColumnTypeByContentLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: defineContentAttribute
public function defineContentAttribute()
{
$maxLength = $this->getSettings()->maxLength;
if (!$maxLength) {
$columnType = ColumnType::Text;
} else {
$columnType = DbHelper::getTextualColumnTypeByContentLength($maxLength);
}
return array(AttributeType::String, 'column' => $columnType, 'maxLength' => $maxLength);
}
示例2: defineContentAttribute
/**
* @inheritDoc IFieldType::defineContentAttribute()
*
* @return mixed
*/
public function defineContentAttribute()
{
if ($this->multi) {
$options = $this->getSettings()->options;
// See how much data we could possibly be saving if everything was selected.
$length = 0;
foreach ($options as $option) {
if (!empty($option['value'])) {
// +3 because it will be json encoded. Includes the surrounding quotes and comma.
$length += strlen($option['value']) + 3;
}
}
if ($length) {
// Add +2 for the outer brackets and -1 for the last comma.
$length += 1;
$columnType = DbHelper::getTextualColumnTypeByContentLength($length);
} else {
$columnType = ColumnType::Varchar;
}
return array(AttributeType::Mixed, 'column' => $columnType, 'default' => $this->getDefaultValue());
} else {
return array(AttributeType::String, 'column' => ColumnType::Varchar, 'maxLength' => 255, 'default' => $this->getDefaultValue());
}
}