I am using the newest version. CakePHP 3.8. I have a few tables associated which itself is associated with other models. In the tables that have, for example, the fields: (id, type_id, category_id), I would like to do something that brings up the following when calling $this->find(‘list’) etc: (1) Personal (type-id) - Category name (category-id)
I have tried creating a behavior but I can’t get it to work. I even tried playing with creating virtual fields but its not working as intended and its rather messy. I declared a function in a behavior (MultipleDisplayField) which am working on but the function is not being called and that is with or without the implementedMethods being declared in the behavior class.
This is the ugliness I came up with in the entity class for the table
protected function _getTypeCategory()
$entityTable = \Cake\ORM\TableRegistry::getTableLocator()->get(‘CategoriesTypes’);
$loaded = $entityTable->loadInto($this, [‘Types’, ‘Categories’]);
‘(’.$this->id.’)’. ’ - ‘.
$loaded->type->name . ’ (’.$loaded->type->id.’) - ‘.
$loaded->category->name . ’ - (’.$loaded->category->id.’)’;
In the table class I have this: $this->setDisplayField(‘type_category’);
As you can see, its not pretty. I would like to have it done in a behavior. Can anyone help with this?
Thanks in advance.