Bitrix Site Manager

CIBlockProperty::Add

int
CIBlockProperty::Add(
 array fields
);

The method adds a new property.

Parameters

ParameterDescription
fields An array in the format Array("field"=>"value"). Contains values of all fields of a property.

You can also set the options for properties of the LIST type. To do so, assign an array Array(array("VALUE"=>"value", "DEF"=>"default (Y/N)", "SORT"=>"sort weight"),...) to the field VALUES. See the UpdateEnum function description for more information.

Return Values

The method returns the property ID on success. In case of failure, it returns false and sets the property LAST_ERROR to the error description.

See Also

  • CIBlockProperty::Update
  • Property fields

    Example


    <?
    $arFields = Array(
      "NAME" => "Colour",
      "ACTIVE" => "Y",
      "SORT" => "100",
      "CODE" => "color",
      "PROPERTY_TYPE" => "L",
      "IBLOCK_ID" => 11
      );
    
    $arFields["VALUES"][0] = Array(
      "VALUE" => "Red",
      "DEF" => "N",
      "SORT" => "100"
    }
    
    $arFields["VALUES"][1] = Array(
      "VALUE" => "Yellow",
      "DEF" => "N",
      "SORT" => "200"
    }
    
    $arFields["VALUES"][2] = Array(
      "VALUE" => "Green",
      "DEF" => "Y",
      "SORT" => "300"
    }
    
    $ibp = new CIBlockProperty;
    $PropID = $ibp->Add($arFields);
    ?>