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.

Data Model Questions /

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

Calling DataObject into Control from other Class ?


Go to End


3 Posts   1961 Views

Avatar
pinkp

Community Member, 182 Posts

8 June 2010 at 9:09pm

How do I get the "$ShWidth" to display inside the control the first one outside is fine but not inside the control....
I want the width the same for every li the other info is variable etc.

I have this in my template:

SlideshowPage.ss

<ul>$ShWidth
				<% control Slideshows %>
				    <li <% if First %>class="show"<% end_if %>><a href="http://$ShLink"><img src="$SlideshowImage.URL" width="$ShWidth" alt="$ShTitle" /></a></li>
				<% end_control %>
				</ul>

SlideshowPage.php

<?php
class SlideshowPage extends Page
{
	
	 static $db = array(
	 		'ShWidth'  => 'Int'

   );
	
	static $has_many = array (
		'Slideshows' => 'Slideshow'
	);
	
	public function getCMSFields()
	{
		$f = parent::getCMSFields();
		
	    $f->addFieldToTab("Root.Content.SlideshowConfiguration", new NumericField('ShWidth','Slideshow Width (pixels)'));
		
		$manager = new DataObjectManager(
			$this, // Controller
			'Slideshows', // Source name
			'Slideshow', // Source class
			array('ShTitle' => 'Title', 'ShLink' => 'Image Link', 'Thumbnail' => 'Image'), // Headings
			'getCMSFields_forPopup' // Detail fields function or FieldSet
			// Filter clause
			// Sort clause
			// Join clause
		);
		
		$f->addFieldToTab("Root.Content.Slideshow", $manager);
		
		return $f;
	}

}
class SlideshowPage_Controller extends Page_Controller
{
}
?>

Slideshow.php

<?php
class Slideshow extends DataObject
{
	static $db = array (
		'ShTitle' => 'Text',
		'ShLink' => 'Text',

			);
	
	static $has_one = array (
		'SlideshowImage' => 'Image',
		'SlideshowPage' => 'SlideshowPage'
	);
	
	
	function Thumbnail() {
	$Image = $this->SlideshowImage();
	if ( $Image ) {
		return $Image->CMSThumbnail();
	} else {
		return null;
	}
}
	
	public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new ImageField('SlideshowImage','Slideshow Image'),
			new TextField('ShTitle','Title'),
			new TextField('ShLink','Image Link')
		);
	}
}
?>

Thanks!

Avatar
Willr

Forum Moderator, 5523 Posts

8 June 2010 at 10:06pm

You need to use $Top.ShWidth. $Top breaks out of the control and references back to the page your on.

Avatar
pinkp

Community Member, 182 Posts

8 June 2010 at 10:50pm

Edited: 08/06/2010 10:51pm

Perfect! as always, many many thanks