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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Multiple DataObject Problem


Go to End


2 Posts   922 Views

Avatar
ambient

Community Member, 130 Posts

11 July 2011 at 9:48am

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 %>

Avatar
ambient

Community Member, 130 Posts

12 July 2011 at 6:52am

Edited: 12/07/2011 6:55am

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