本文整理匯總了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);
}