Jump to:

3395 Posts in 977 Topics by 853 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: 1219 Views
  • nakashu
    Avatar
    Community Member
    24 Posts

    basic boolean function creation - newbie Link to this post

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

    <?php

    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
             array(
                //'Thumbnail' => 'Image',
                'Name' => 'Name',
                'Caption' => 'Caption'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
             
          );
          $manager->setAllowedFileTypes(array('jpg','png','flv'));
          $manager->allowUploadFolderSelection();
                
          $f->removeFieldFromTab("Root.Content.Main","Content");
    $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;         
             else
                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.

    thanks

  • Hamish
    Avatar
    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.

    1219 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.