A
A
Alexander2020-02-18 12:27:53
ORM
Alexander, 2020-02-18 12:27:53

How to create a file field for an entity?

I have an entity one of the fields of which should be a file.

Well, let's say this:

class MessageTable extends \Bitrix\Main\Entity\DataManager
{

    public static function getMap()
    {
        return array(
      new Entity\IntegerField('ID', array(
        'primary' => true,
        'autocomplete' => true
      )),
            new Entity\IntegerField('AUTHOR', array( 
                'required' => true
            )),
      new Entity\StringField('TEXT'),
      new Entity\IntegerField('FILE')
        );
    }
  
}


So far I have made it IntegerField and I am going to save the file in the file table and write the id there, and write the code that will serve the addition / deletion of the file + smear with deletion hooks, an entity element that will delete the file from the file table.

Perhaps there is another way?
Or someone already implemented this - I can not find it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikolaev, 2020-02-18
@gromdron

There is another way and it is quite simple: you write that the entity works with properties and add a UF_* property of the file type (or a file on disk) and Bitrix does everything for you. The only thing is there are a few restrictions:
- The field is called with the UF_ prefix
- Validation according to the field settings
- You need to add uf separately

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question