本文整理汇总了PHP中CustomFieldData::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP CustomFieldData::getById方法的具体用法?PHP CustomFieldData::getById怎么用?PHP CustomFieldData::getById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CustomFieldData
的用法示例。
在下文中一共展示了CustomFieldData::getById方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSaveAndLoadCustomFieldData
public function testSaveAndLoadCustomFieldData()
{
$values = array('Item 1', 'Item 2', 'Item 3');
$labels = array('fr' => 'Item 1 fr', 'fr' => 'Item 2 fr', 'fr' => 'Item 3 fr');
$customFieldData = CustomFieldData::getByName('Items');
$customFieldData->serializedData = serialize($values);
$customFieldData->serializedLabels = serialize($labels);
$this->assertTrue($customFieldData->save());
$id = $customFieldData->id;
unset($customFieldData);
$customFieldData = CustomFieldData::getById($id);
$loadedValues = unserialize($customFieldData->serializedData);
$loadedLabels = unserialize($customFieldData->serializedLabels);
$this->assertEquals('Items', $customFieldData->name);
$this->assertNull($customFieldData->defaultValue);
$this->assertEquals($values, $loadedValues);
$this->assertEquals($labels, $loadedLabels);
$customFieldData->defaultValue = $values[2];
$this->assertTrue($customFieldData->save());
unset($customFieldData);
$customFieldData = CustomFieldData::getById($id);
$this->assertEquals('Items', $customFieldData->name);
$this->assertEquals('Item 3', $customFieldData->defaultValue);
$this->assertEquals($values, $loadedValues);
}
示例2: testSetAndGetEmptyValueWhichShouldUtilizeFallBack
public function testSetAndGetEmptyValueWhichShouldUtilizeFallBack()
{
$this->assertEquals('en', Yii::app()->language);
$values = array('Item 1', 'Item 2', 'Item 3');
$labels = array('fr' => array('Item 1 fr', '', 'Item 3 fr'));
$customFieldData = CustomFieldData::getByName('Items2');
$customFieldData->serializedData = serialize($values);
$customFieldData->serializedLabels = serialize($labels);
$this->assertTrue($customFieldData->save());
$id = $customFieldData->id;
$customFieldData->forget();
unset($customFieldData);
$customFieldData = CustomFieldData::getById($id);
$dataAndLabels = CustomFieldDataUtil::getDataIndexedByDataAndTranslatedLabelsByLanguage($customFieldData, 'en');
$compareData = array('Item 1' => 'Item 1', 'Item 2' => 'Item 2', 'Item 3' => 'Item 3');
$this->assertEquals($compareData, $dataAndLabels);
$dataAndLabels = CustomFieldDataUtil::getDataIndexedByDataAndTranslatedLabelsByLanguage($customFieldData, 'fr');
$compareData = array('Item 1' => 'Item 1 fr', 'Item 2' => 'Item 2', 'Item 3' => 'Item 3 fr');
$this->assertEquals($compareData, $dataAndLabels);
}
示例3: testGetTranslatedLabelByValue
public function testGetTranslatedLabelByValue()
{
$this->assertEquals('en', Yii::app()->language);
$values = array('Item 1', 'Item 2', 'Item 3');
$labels = array('fr' => array('Item 1 fr', '', 'Item 3 fr'));
$customFieldData = CustomFieldData::getByName('Items2');
$customFieldData->serializedData = serialize($values);
$customFieldData->serializedLabels = serialize($labels);
$this->assertTrue($customFieldData->save());
$id = $customFieldData->id;
$customFieldData->forget();
unset($customFieldData);
$customFieldData = CustomFieldData::getById($id);
$value = CustomFieldDataUtil::getTranslatedLabelByValue($customFieldData, 'Item 1', 'en');
$this->assertEquals('Item 1', $value);
$value = CustomFieldDataUtil::getTranslatedLabelByValue($customFieldData, 'Item 1', 'fr');
$this->assertEquals('Item 1 fr', $value);
}