Jump to:

3447 Posts in 1032 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » basic boolean function creation - newbie

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

Page: 1
Go to End
Author Topic: 1270 Views
  • nakashu
    Community Member
    24 Posts

    basic boolean function creation - newbie Link to this post

    Got a newbie question,
    as am SS and php beginer somehow cant get this function to work.


    class GalleryPage extends Page
       static $has_many = array (
          'GalleryImages' => 'GalleryImage'
       public function getCMSFields()
          $f = parent::getCMSFields();
          $manager = new FileDataObjectManager(
             $this, // Controller
             'GalleryImages', // Source name
             'GalleryImage', // Source class
             'Resource', // File name on DataObject
                //'Thumbnail' => 'Image',
                'Name' => 'Name',
                'Caption' => 'Caption'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
    $f->addFieldToTab("Root.Content.Main", $manager, "Content_Caption");
          return $f;

    class GalleryPage_Controller extends Page_Controller {   
          public function IsFLV()         
          $res = $this->Resource;
          $ext = $res->getExtension();
             if ($ext == 'flv')
                return true;         
                return false;


    what i want to do is to get the Resource(is a file) extension, find out if it is and flv and return boolean.
    i know the above syntax isnt right, but cant figure out how it should be.
    tried different ways, mostly the $res is empty, or the page wont load at all.


  • Hamish
    Community Member
    712 Posts

    Re: basic boolean function creation - newbie Link to this post

    GalleryPage doesn't have a "Resource" object, so $this->Resource will not return anything.

    What are you trying to do?

    I see that GalleryPage has many associated GalleryImages - is this what you are looking at? If so, you need to decide which GalleyImage you want to test, since it is not a 'one - one' relationship.

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.