Documentation

Add

Description and parameters

int
 CIBlock::Add(
 array arFields
);

Method adds a new iblock. You can modify fields, as well as cancel creating an iblock by adding an event handler OnBeforeIBlockAdd. On successfully added iblock, calls the event handlers OnAfterIBlockAdd. Non-static method.

Parameters

ParameterDescription
arFields Array("field"=>"value", ...). Contains values for iblock's [link=90637#fiblock]all fields[/link].

Additionally, the field SITE_ID must contain array with site IDs with associated added iblock.

In addition to this, you can assign iblock access permissions (see. [link=90643]CIBlock[/link]::[link=90651]SetPermission()[/link]) for various groups using the field "GROUP_ID", containing the array with group codes matching access permissions.

When the field "FIELDS", is set, executes the iblock field settings (see. [link=126629]CIBlock::SetFields[/link]).

Additionally, the field "VERSION", defining the method of storage for iblock element properties (1 - in general table | 2 - in a separate). Accepts value 1 by default.

When required to add an iblock with workflow support, indicate two additional fields: BIZPROC, receiving value Y, and WORKFLOW, receiving value N.

Returned value

Method returns code for added iblock on success, or returns false on error and LAST_ERROR object property will contain error text.

See Also

  • [link=90653]CIBlock::Update[/link]
  • [link=90637#fiblock]Iblock fields[/link]
  • [link=90715]OnBeforeIBlockAdd[/link]
  • [link=90707]OnAfterIBlockAdd[/link]
  • [link=126629]CIBlock::SetFields[/link]

Example

<?
$arPICTURE = $_FILES["PICTURE"];
$ib = new CIBlock;
$arFields = Array(
"ACTIVE" => $ACTIVE,
"NAME" => $NAME,
"CODE" => $CODE,
"LIST_PAGE_URL" => $LIST_PAGE_URL,
"DETAIL_PAGE_URL" => $DETAIL_PAGE_URL,
"IBLOCK_TYPE_ID" => $type,
"SITE_ID" => Array("en", "de"),
"SORT" => $SORT,
"PICTURE" => $arPICTURE,
"DESCRIPTION" => $DESCRIPTION,
"DESCRIPTION_TYPE" => $DESCRIPTION_TYPE,
"GROUP_ID" => Array("2"=>"D", "3"=>"R")
);
if ($ID > 0)
$res = $ib->Update($ID, $arFields);
else
{
$ID = $ib->Add($arFields);
$res = ($ID>0);
}
?>

© «Bitrix24», 2001-2024
Up