Documentation

SetPropertyValuesEx

CIBlockElement::SetPropertyValuesEx(
   int ELEMENT_ID,
   int IBLOCK_ID,
   array PROPERTY_VALUES,
   array FLAGS = array()
);

The method saves values of all iblock element properties. In contrast to SetPropertyValues may not contain a complete set of values. Property values not specified in the array PROPERTY_VALUES will be saved. This method is more efficient in terms of amount of queries to the database. Static method.

The method returns Null.

When empty value must be saved for multiple property, use false, because an empty array won't be saved.

Call parameters

  • DoNotValidateLists - disables availablility check for the metadata values of list properties.

  • ParameterDescription
    ELEMENT_ID Element ID with properties to be set.
    IBLOCK_ID Information block ID. Optional. Read from database via element ID when not specified.
    PROPERTY_VALUES Array of property values. Contains a corresponding property value assigned to the property ID.
    Must have the type: Array("property code1"=>"property value1", ....), where "property code" - numerical or symbolic property code, "property values" - single value or array of all property values (multiple).

    Notes:
    • When adding the "File" type property values, the DESCRIPTION field is required.
    • When an array "property"=>"value" is passed, specify an external element ID for "selection list" property type.

    • For the List property type, pass a property ID, not the property value.
    • For the property type of Bind to file on server, pass a path to the file from the site root.
    FLAGS Optional parameter provides information to optimize execution. Can contain the following keys:
    • NewElement - to be specified when this element already has no property values. Prevents one redundant query to the database.

    See Also

    Examples

    Example 1:

    <?
    $ELEMENT_ID = 18; // element ID
    $PROPERTY_CODE = "PROP1"; // property ID
    $PROPERTY_VALUE = "Blue"; // property value

    // Set new value for this element property
    CIBlockElement::SetPropertyValuesEx($ELEMENT_ID, false, array($PROPERTY_CODE => $PROPERTY_VALUE));

    ?>

    Example 2 (modifying single value property of HTML/Text type):

    $el_id = 125;
    $iblock_id = 45;
    $prop[$prop_code] = array('VALUE'=>array('TYPE'=>'HTML', 'TEXT'=>$prop_value));
    CIBlockElement::SetPropertyValuesEx($el_id, $iblock_id, $prop);
    

    Example 3:

    <input name="MyFile1" type="file" />
    <input name="MyFile2" type="file" />
    
    function makeCurentFilesArray($InputFileCode) {
       unset($arFiles, $TMPFILE);
       $arFiles = array();  // Array of all files within property []
       $TMPFILE = array(); // Temporary array for current file
       if(is_array($_FILES[$InputFileCode])) {
          foreach($_FILES[$InputFileCode]['tmp_name'] as $key => $val) {
             if(file_exists($val)) { 
                foreach($_FILES[$InputFileCode] as $namekey => $nameval) {
                   $TMPFILE[$namekey] = $nameval[$key];
                }
             $arFiles[] = array('VALUE' => $TMPFILE, 'DESCRIPTION' => $TMPFILE['name']); 
             }
          } 
       } 
       return $arFiles;
    }
    
    if (!empty($_FILES['MyFile1'])) $PropFileArr['MyFile1'] = makeCurentFilesArray('MyFile1');   
    if (!empty($_FILES['MyFile2'])) $PropFileArr['MyFile2'] = makeCurentFilesArray('MyFile2');
                           
    CIBlockElement::SetPropertyValuesEx($Element_ID, $IBlock_ID, $PropFileArr); // Update file propert array
    
    © «Bitrix24», 2001-2024
    Up