Jump to:

23451 Posts in 18899 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » accessing filename through PHP

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

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

Page: 1
Go to End
Author Topic: 823 Views
  • Bruce B
    Avatar
    Community Member
    145 Posts

    accessing filename through PHP Link to this post

    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

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: accessing filename through PHP Link to this post

    $this->mp4video()->Filename

  • Bruce B
    Avatar
    Community Member
    145 Posts

    Re: accessing filename through PHP Link to this post

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

    many thanks.

    823 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.