# Работа с объектами ORM

Вывести перевод для текущего языка элемента определённого поля можно так (если перевода нет, то вернет значения дефолтного языка)

{% code lineNumbers="true" fullWidth="true" %}

```php
$oInformationsystem_Item = Core_Entity::factory('Informationsystem_Item', 123);
echo $oInformationsystem_Item->multiLng('name'); // About

// для доп. свойства
$oProperty = Core_Entity::factory('Property', 123);
$aPropertyValues = $oProperty->getValues($shop_item_id);  
echo $aPropertyValues[0]->multiLng('value')
```

{% endcode %}

Получить все переводы всех полей для элемента в виде объектов

{% code lineNumbers="true" fullWidth="true" %}

```php
/* 
 * Получение маасива объектов, $bCache = TRUE
 * @param string $entity model name
 * @param int $entity_id
 * @param boolean $type FALSE|TRUE
 * @param boolean $bCache cache mode
 * @return array
 */
Core_Entity::factory('MultiLanguage_Field')->getAFields('shop_item', 123);

// Результат
//Array (
//	[0] => MultiLanguage_Field_Model Object
//	[1] => MultiLanguage_Field_Model Object
//)

/* 
 * Получение массива объектов с ключами полей
 */
Core_Entity::factory('MultiLanguage_Field')->getAFields('shop_item', 123, TRUE);

// Результат
//Array (
//	[name] => MultiLanguage_Field_Model Object
//	[description] => MultiLanguage_Field_Model Object
//)

/* 
 * Получение объекта по полю
 * @param string $entity model name
 * @param int $entity_id
 * @param string $field field name
 * @param boolean $bCache cache mode
 * @return self|NULL
 */
Core_Entity::factory('MultiLanguage_Field')->getByField('shop_item', 123, 'name');
```

{% endcode %}

## Сохранение перевода для элемента

Сохранение происходит через параметр `datalng_{lng}_{field}`, где {lng} это код языка, а {field} имя поля элемента

{% code lineNumbers="true" fullWidth="true" %}

```php
$oInformationsystem_Item = Core_Entity::factory('Informationsystem_Item', 123);
$oInformationsystem_Item->datalng_en_name = 'My name';
$oInformationsystem_Item->save();
```

{% endcode %}

{% code lineNumbers="true" fullWidth="true" %}

```php
// получаем текущий язык


// получение 
```

{% endcode %}

Вывести домен текущего язык&#x430;*, для типа <mark style="color:yellow;">**\[site]**</mark>*

{% code lineNumbers="true" fullWidth="true" %}

```php
$oMultiLanguage = Core_Entity::factory('MultiLanguage')->getByLng(Core::getLng());
    
if(!is_null($oMultiLanguage)
    echo $oMultiRegion->Site_Alias->name; // msk.site.ru
```

{% endcode %}

Вывести путь текущего язык&#x430;*, для типа <mark style="color:yellow;">**\[url]**</mark>*

{% code lineNumbers="true" fullWidth="true" %}

```php
<?php
$lngPath = '';

$oMultiLanguage = Core_Entity::factory('MultiLanguage')->getByLng(Core::getLng());
!is_null($oMultiLanguage) && $lngPath = $oMultiLanguage->getPath();

?>

<a href="/<?php echo $lngPath ?>politics/">Политика конфиденциальности
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://support.morozovpimnev.ru/multilanguage/rabota-s-obektami-orm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
