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

how do i access fields i have created


Go to End


4 Posts   1019 Views

Avatar
zim

Community Member, 135 Posts

1 November 2009 at 3:23am

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

Community Member, 135 Posts

1 November 2009 at 4:20am

I have solved this now.

Avatar
Juanitou

Community Member, 323 Posts

1 November 2009 at 6:25am

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

Community Member, 135 Posts

1 November 2009 at 6:53am

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>