Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Limiting Results of Control

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1088 Views
  • VictorH
    Avatar
    Community Member
    29 Posts

    Limiting Results of Control Link to this post

    I have the following code that displays all the posters belonging to the Movie Page. I'm using the same code on the Homepage as I'm using a specific function to pull in the Movie pages on the homepage. On the homepage I want to limit the number of posters to 4. I can't seem to do this any help?

    <ul class="movieList">
          <% control MoviePages %>
             <li>
                <h2><a href="$Link">$Title<% if MovieVersion %> <span>($MovieVersion)</span><% end_if %></a></h2>
                <% if ReleaseDate %><p><strong>Release Date:</strong> $ReleaseDate.Nice</p><% end_if %>
                <h3>Sypnosis</h3>
                $Content            
                <h3>Posters</h3>
                <% if Posters %>
                   <ul class="posters clear">
                      <% control Posters(4) %>
                         <li>
                            <a href="<% control PosterImage %>$URL<% end_control %>" title="$Pos/$TotalItems - $PosterName" rel="$MoviePage.Title"><% control PosterImage %><img src="<% control CroppedImage(125,188) %>$URL<% end_control %>" alt="$Title Poster Thumbnail" width="<% control CroppedImage(125,188) %>$Width<% end_control %>" height="<% control CroppedImage(125,188) %>$Height<% end_control %>" /><% end_control %><span></span></a>
                         </li>
                      <% end_control %>
                   </ul>
                <% else %>
                   <h5>No Posters Yet</h5>
                   <p>Do you have a poster for this movie? Please <a href="contact">send it to us</a> so we can add it to the site.</p>
                <% end_if %>
             </li>
          <% end_control %>
       </ul>

  • UncleCheese
    Avatar
    4085 Posts

    Re: Limiting Results of Control Link to this post

    You just need to write a custom getter..

    function HomePosters()
    {
    return $this->Posters(null, null, null, 4);
    }

  • VictorH
    Avatar
    Community Member
    29 Posts

    Re: Limiting Results of Control Link to this post

    I tried doing this:
    Homepage.php

    function MoviePosters() {
          $doSet = DataObject::get(
             $callerClass = "Poster",
             $filter = "`MoviePageID` = '".$this->ID."'",
             $sort = "Sort DESC",
             $join = "",
             $limit = "0,4"
          );
          return $doSet ? $doSet : false;
       }


    Homepage.ss

    <% control MoviePosters %>
                   test
                <% end_control %>

    It doesn't produce anything.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Limiting Results of Control Link to this post

    $filter = "`MoviePageID` = '".$this->ID."'",

    MoviePages are associated with your homepage? Seems odd.

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