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.

General Questions

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

how do i access fields i have created


Reply

4 Posts   741 Views

Avatar
zim

1 November 2009 at 3:23am Community Member, 135 Posts

I have created a VideoImage tab on my homepage.php like this

class HomePage extends Page {
static $db = array(
);
static $has_one = array(
    'VideoImage' => 'Image',
    'VideoTitle' => 'Text',
    'VideoLink' => 'Text'
);

function getCMSFields() {
$fields = parent::getCMSFields();
   
      $fields->addFieldToTab('Root.Content.VideoImage', new ImageField('VideoImage'), 'Content');
      $fields->addFieldToTab('Root.Content.VideoImage', new TextField('VideoTitle'), 'Content');
      $fields->addFieldToTab('Root.Content.VideoImage', new TextField('VideoLink'), 'Content');

return $fields;
      }

so I have a video image tab with VideoImage, VideoTitle, VideoLink

I can't seem to access these now on my HomePage.ss. I thought it would just be $VideoImage.URLSegment, $VideoTitle, $VideoLink but this does not pull in values.

I have tried $Content.VideoTitle too and does not work. Can anyone point me in right direction. I know must be basic.

Avatar
zim

1 November 2009 at 4:20am Community Member, 135 Posts

I have solved this now.

Avatar
Juanitou

1 November 2009 at 6:25am Community Member, 323 Posts

Hi zim!

I guess your error was in that $has_one array, which was not referencing DataObjects, but it’d be nice to explain the solution you found, for beginners.

Regards,
Juan

Avatar
zim

1 November 2009 at 6:53am Community Member, 135 Posts

Hey dude i am more than happy to show the solution. i am new to this too and didn't want to look stupid :)

this is what I changed it too ... so yes it was the what you say i guess. i put them all onto the main tab in cms as well. it seems to work now so i can now upload a picture title and link and click off to say a youtube vid.. i am currently trying to then get this link to pop youtube link into nice light box.... am trying to use prettyphoto jquery plug in but not working yet.

class HomePage extends Page {
static $db = array(
    'VideoTitle' => 'Text',
    'VideoLink' => 'Text'
);
static $has_one = array(
    'VideoImage' => 'Image'
);

function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Content.Main', new ImageField('VideoImage'));
$fields->addFieldToTab('Root.Content.Main', new TextField('VideoTitle'));
$fields->addFieldToTab('Root.Content.Main', new TextField('VideoLink'), 'Content');

return $fields;
}

then I can just accesss the fields like this

<a href="$VideoLink" rel="prettyPhoto"><img src="themes/tutorial/images/home/btn_video_play.png" alt="play"></a>

<a href="$VideoLink" rel="prettyPhoto">$VideoTitle</a>

<a href="$VideoLink" rel="prettyPhoto"><img src="$VideoImage.URL" alt="picture"></a>