Documentation

GetProperty

CDBResult
  CIBlockElement::GetProperty(
  int iblock_id,
int element_id,
array arOrder = Array(), array arFilter = Array() );

This method returns property values for the element element_id. Static method.

Parameters

ParameterDescription
iblock_id Iblock code.
element_id Element code.
arOrder
Array(by1=>order1[, by2=>order2 [, ..]]), where by - sorting field, can receive values:
  • id - property code;
  • sort - sort index;
  • name - property name;
  • active - property active status;
  • value_id - property code value;
  • enum_sort - sort index for variant of list property; 
order - sort order, can receive values:
  • asc - by ascending;
  • desc - by descending;
Optional. By default is set as Array("sort"=>"asc")
Note: parameter mustn't be false, otherwise method operates incorrectly and result won't be fetched by specified criteria.
arFilter Array("filtered field"=>"filter values" [, ...]) "filtered field" can receive values: ACTIVE - active status (Y/N),
  • NAME - property name (can use the mask %|_),
  • ID - property code,
  • ACTIVE - active status (Y|N),
  • SEARCHABLE - listing status (Y|N),
  • PROPERTY_TYPE - property type,
  • CODE - property symbolic code,
  • EMPTY - property emptiness attribute (Y|N).
Optional parameter, by default equals to array().

Note: Существуют ещё параметры, оставленные для сохранения совместимости: $by и $order .

Returned value

Returns the object CDBResult, containing property fields and fields with values:


PROPERTY_VALUE_ID - property code values,
VALUE - property value,
DESCRIPTION - property value description,
VALUE_ENUM - text value for list item property,
VALUE_XML_ID - external code for "list" property value.

Examples

Example 1:

<?
$db_props = CIBlockElement::GetProperty($PRODUCT_IBLOCK_ID, $PRODUCT_ID, array("sort" => "asc"), Array("CODE"=>"FORUM_TOPIC_ID"));
if($ar_props = $db_props->Fetch())
$FORUM_TOPIC_ID = IntVal($ar_props["VALUE"]);
else
$FORUM_TOPIC_ID = false;
?>

Example 2 (getting value for multiple property):

    $VALUES = array();
    $res = CIBlockElement::GetProperty(IKSO_CUSTOM::$IBLOCKS['brands'], $BRAND_ID, "sort", "asc", array("CODE" => "BRAND_CLASS"));
    while ($ob = $res->GetNext())
    {
        $VALUES[] = $ob['VALUE'];
    }

Example 3 (getting values for non-multiple property):

$res = CIBlockElement::GetProperty(IKSO_CUSTOM::$IBLOCKS['brands'], $BRAND_ID, "sort", "asc", array("CODE" => "BRAND_CLASS"));
    if ($ob = $res->GetNext())
    {
        $VALUE = $ob['VALUE'];
    }

Example 4:

When property has no values and filter doesn't receive "EMPTY"=>"N", the method returns array with an empty key VALUE:

//uses Iblocks 2.0
$db_props = CIBlockElement::GetProperty(30, 14391, "sort", "asc", Array("CODE"=>"XXX")); // XXX - "String" multiple property
if($ar_props = $db_props->Fetch()):
echo "<pre>".print_r($ar_props, true)."<pre>";
endif;

Example 5

When you need to get names for list type values

?
$res = CIBlockElement::GetProperty(ID_BLOKA, ID_ELEMENTA, array("sort" => "asc"), Array("CODE"=>"CATEGORIES"));
     while ($ob = $res->GetNext()) {
          $prop = $ob['VALUE_ENUM'];
          echo $prop. "
"; } ?
© «Bitrix24», 2001-2024