Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Multiple DataObject Problem

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: 698 Views
  • ambient
    Avatar
    Community Member
    123 Posts

    Multiple DataObject Problem Link to this post

    Hi All,

    I am trying to show different news summaries on different pages. I am not very good with PHP but am trying to improve.

    I've used the news article from tutorial 2 as my foundation.
    For example if I have a sports news page that i want to show on some pages
    and then a local news page that i want to show on some other pages etc. etc.

    The plan is to have a drop down box in the cms to choose which news section to display on each page.

    The problem is I can't even get a second summery to show on any page. As soon as I replicate the code, changing function and control names, the page gets a server error with no explanation.

    Below are some snippets of my code.
    Could anyone please take a look and explain what I'm doing wrong or suggest a better way of doing it. I've been battling this for days

    Page.php

    function NewsListGreen($num=5) {
    $green = DataObject::get_one("NewsHolder");
    return ($green) ? DataObject::get("NewsGreenPage", "ParentID = $green->ID", "Date DESC", "", $num) : false;
    }

    Page.ss

    <% control NewsListGreen %>

    <div class="News_listing_box"><!--start News_listing_box-->

    <div class="News_listing_img"><!--start News_listing_img-->
    <a href="$PageLink.Link">$Img</a>
    </div><!--end News_listing_logo-->

    <div class="News_link $BorderColor"><!--start News_listing_link-->
    <a href="$PageLink.Link"><h2>Read More</h2></a>
    </div><!--endNews_listing_link-->

          

       </div>
    <% end_control %>

    HomePage.php

       function NewsListGold($num=7) {
    $gold = DataObject::get_one("NewsHolder");
    return ($gold) ? DataObject::get("NewsGoldPage", "ParentID = $gold->ID", "Date DESC", "", $num) : false;
    }

    HomePage.ss

    <% control NewsListGold %>

    <div class="News_listing_box"><!--start News_listing_box-->

    <div class="News_listing_img"><!--start News_listing_img-->
    <a href="$PageLink.Link">$Img</a>
    </div><!--end News_listing_logo-->

    <div class="News_link $BorderColor"><!--start News_listing_link-->
    <a href="$PageLink.Link"><h2>Read More</h2></a>
    </div><!--endNews_listing_link-->

    <% end_control %>

  • ambient
    Avatar
    Community Member
    123 Posts

    Re: Multiple DataObject Problem Link to this post

    I think I may be in the wrong forum. I've moved this to general questions

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