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.

Data Model Questions

Calling DataObject into Control from other Class ?


Reply

3 Posts   1279 Views

Avatar
pinkp

8 June 2010 at 9:09pm Community Member, 168 Posts

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

8 June 2010 at 10:06pm Forum Moderator, 5511 Posts

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

Avatar
pinkp

8 June 2010 at 10:50pm (Last edited: 8 June 2010 10:51pm), Community Member, 168 Posts

Perfect! as always, many many thanks