Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Calling DataObject into Control from other Class ?

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

Page: 1
Go to End
Author Topic: 1205 Views
  • pinkp
    Avatar
    Community Member
    168 Posts

    Calling DataObject into Control from other Class ? Link to this post

    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!

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Calling DataObject into Control from other Class ? Link to this post

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

  • pinkp
    Avatar
    Community Member
    168 Posts

    Re: Calling DataObject into Control from other Class ? Link to this post

    Perfect! as always, many many thanks

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