Is it possible to implement a relation behavior with an image?


Is it possible to implement a relation behavior with an image?

I have an image model and controller, which works standalone, but not inside another model as a Relation Behavior.

Did I maybe implement something wrong or doesn’t this work by default?

Well, it is possible. I don’t know what I did wrong before.

So this is a nice solution of having different information to an image like a name and a richtexteditor field and having multiple of them in another “main” model.

This kind of replaces having an image in a repeater field, which I would like to have a lot…

What was an issue, is to show the images in the columns of the submodel. The main model complaint of not having an image column field. So I just did a new DB field, where I save the image model as well.

Here’s my DB structure of the image model:


Here is what I do in the image model beforeSave:

public function beforeSave() {
    $this->images = $this->images_of_the_week;

So then I’m able to have a partial column field in the image model like this:

    label: Bild
    type: partial
    path: ~/plugins/creationhandicap/startpage/controllers/images/_image.htm
    searchable: false
    sortable: false

The partial then looks like this:

    if (isset($record->images)) {
        $imagePath = $record->images['path'];
        $imageFileName = $record->images['file_name'];
        echo '<img src="'. $imagePath .'" alt="'. $imageFileName .'" style="height: 80px; width: 80px; object-fit: cover; border-radius: 2px;" />';
    } else {
        echo 'Kein Bild vorhanden';

If somebody struggles to achive the same, please let me know here…