Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

accessing filename through PHP


Go to End


3 Posts   1156 Views

Avatar
Bruce B

Community Member, 164 Posts

6 November 2009 at 12:56pm

I'm attempting to add video to a page using the HTML5 code suggested by Mark Pilgrim. I can upload the video files and can show the video on the page but haven't succeeded in joining the two ends together.
I created a new has-one relationship:
'mp4video' => 'File',
and set up the CMS fields to upload the files.

How do I get the file path in PHP? In the template I can use $mp4video.filename and it shows the correct data but any attempt to get info from $this->mp4video just generates an error message about trying to get the properties of a non-object.

I am currently doing this:
$mp4object = DataObject::get_by_id('File', $this->getField('mp4videoID'));
$mp4path = $mp4object->getField('Filename');

but it seems a roundabout route. Can someone help with what must be a very basic hole in my knowledge?

cheers
bruce

Avatar
ajshort

Community Member, 244 Posts

6 November 2009 at 2:31pm

$this->mp4video()->Filename

Avatar
Bruce B

Community Member, 164 Posts

6 November 2009 at 3:12pm

I knew it was simple. I just couldn't find an example.

many thanks.