Views: 8941
Last Modified: 19.09.2014

Ways of Data Transmission among Components:

  1. Global variables. For example:
    $GLOBALS['mycomponent_variable'] = $arResult["ID"];

    In addition to GLOBALS you can also use $_SESSION provided that:

    • The volume of data is not big;
    • Immediately after transmission, the data will be deleted from $_SESSION, otherwise, they will be “alive” so long as the session is active.
  2. Wrapper class, for example:
    Class GarbageStorage{
       private static $storage = array();
       public static function set($name, $value){ self::$storage[$name] = $value;}
       public static function get($name){ return self::$storage[$name];}
    }
    Accordingly, the use:
    \GarbageStorage::set('MyCustomID', $arResult["ID"]); #set the value
    \GarbageStorage::get('MyCustomID'); #obtain the value

Choose the way depending on the components, on what, exactly, you want to transmit to another component, and whether or not there are necessary data available in non-cached files (speaking of component_epilog.php). The use of the wrapper class is more difficult but far more correct.



Courses developed by Bitrix24