Documentation

add

Attention! We strongly recommend first to learn more about Sites module REST documentation to understand how the module functions (with REST available in Bitrix24 Self-hosted editions). View this documentation as useful source when working with Bitrix24 Self-hosted editions and when you want to learn more about API.

public static function Site::add(
   $fields
);

Adds a site.

Parameters

ParameterDescriptionVersion
$fieldsArray of site parameters. Array keys:
  • TITLE - site name
  • DOMAIN_ID - domain ID
  • CODE - site code. CODE must be unique within domain when adding and updating a site.
  • SMN_SITE_ID - main module site ID. See details below

Example

if (\Bitrix\Main\Loader::includeModule('landing'))
{
   $res = \Bitrix\Landing\Site::add(
      [
         'TITLE' => 'New site',
         'DOMAIN_ID' => 1,
         'CODE' => 'tratata'
      ]
   );
   if ($res->isSuccess())
   {
      echo 'new id: ' . $res->getId();
   }
   else
   {
      print_r($res->getErrors());
   }
}

Historically, Bitrix24 Sites24 are located in public sections (for both Self-hosted and Cloud).

Single Site24 is associated with a single main module site. Such connection is automatic when entering Sites24 menu. The field SMN_SITE_ID governs such association. For example:

if (\Bitrix\Main\Loader::includeModule('landing'))
{
   $res = \Bitrix\Landing\Site::add(
      [
         'TITLE' => 'New site',
         'DOMAIN_ID' => 1,
         'CODE' => 'tratata',
         'SMN_SITE_ID' => 's1'
      ]
   );
   if ($res->isSuccess())
   {
      echo 'new id: ' . $res->getId();
   }
   else
   {
      print_r($res->getErrors());
   }
}

Creating using template

Developers may need to create site using a template displayed in the site or landing page interface. It can be done starting from module version 18.6.0 by directly querying a demo template component.

// connect the component and initiate it via parameters
$componentName = 'bitrix:landing.demo';
$className = \CBitrixComponent::includeComponentClass($componentName);
$demoCmp = new $className;
$demoCmp->initComponent($componentName);
$demoCmp->arParams = array(
   'TYPE' => 'STORE',// PAGE – standard site, STORE – online store
   'DISABLE_REDIRECT' => 'Y'
);
// get list of site demo templates
$tpl = $demoCmp->getDemoSite();
// and pages
$tpl = $demoCmp->getDemoPage();
// array keys $tpl are template code to be passed into next method 
$demoCmp->actionSelect('app');

Please note, catalog import is not performed via this example in case of online store. Also note, that this code is for illustrating API applicability only.



© «Bitrix24», 2001-2024
Up