Photo.URL doesnt work

Hi I created DataObject - Banner:

<?php

use SilverStripe\ORM\DataObject;
use SilverStripe\Assets\Image;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\AssetAdmin\Forms\UploadField;

class Banner extends DataObject {
	
    private static $db = array (
        'Nadpis' => 'Text',
		'Popis' => 'Text',
		'Link' => 'Text',
    );

    private static $has_one = array (
        'Obrazok' => 'Image',
		'Page' => 'Page'
    );
	
	 private static $summary_fields = array (
        'GridThumbnail' => '',
        'Nadpis' => 'Nadpis',
		'Popis' => 'Popis',
		'Link' => 'URL adresa odkazu',
    );

    public function getGridThumbnail() {
        if($this->Obrazok()->exists()) {
            return $this->Obrazok()->ScaleWidth(100);
        }

        return "(no image)";
    }

    public function getCMSFields() {
        $fields = FieldList::create(
            TextField::create('Nadpis'),
			TextField::create('Popis'),
			TextField::create('Link'),
            $uploader = UploadField::create('Obrazok')
        );

        $uploader->setFolderName('banner-uvodna');

        return $fields;
    }
}

class Banner_Controller extends PageController {
	
}

And I add it on Homepage:

<?php

use SilverStripe\Forms\TextField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;

class HomePage extends Page {
	
		
    private static $db = [
		'Box1' => 'HTMLText',
		'Box2' => 'HTMLText',
		'Box3' => 'HTMLText',
		
	];

    private static $has_one = [];
	
	private static $has_many = array (
		'Bannery' => 'Banner',
	);


	
	public function getCMSFields() {
		
		$fields = parent::getCMSFields();
		
		$fields->addFieldToTab('Root.Main', $Box1Field = HtmlEditorField::create('Box1','Box pod bannerom 1'),'Content');
		
		$fields->addFieldToTab('Root.Main', $Box2Field = HtmlEditorField::create('Box2','Box pod bannerom 2'),'Content');
		
		$fields->addFieldToTab('Root.Main', $Box3Field = HtmlEditorField::create('Box3','Box pod bannerom 3'),'Content');
		
		$fields->addFieldToTab('Root.Bannery', GridField::create(
            'Bannery',
            'Vloženie banneru na úvodnú stránku',
            $this->Bannery(),
            GridFieldConfig_RecordEditor::create()
        ));
		
		
		return $fields;
	}  
}

But When I call URL on Homepage.ss I get empty string. “Nadpis”, “Popis” and “Link” having good value.

LINK on page: http://bbl.fianza.sk/

A couple of things which are possibly the issue:

In your has_one relations, you’d be better off using the full classname, eg:

private static $has_one = [ 'Obrazok' => Image::class, 'Page' => Page::class ];

(And the same in your HomePage class too)

You haven’t posted your template code, so it’s a bit of guesswork here. Bannery is a has_many relationship, so it will return a data list, meaning you can’t just access a URL without more info.

What I think you’ll need is something like $Bannery.First.Obrazok.URL in order to get to the image. If that doesn’t work, can you post the relevant part of your template and hopefully it will be clearer.

Thx. ::class worked. I also change Photo.URL for Photo.Link and delete widht for Image, because I used SS 4.2.1