3069 Posts in 868 Topics by 650 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 845 Views |
-
Multiple referenced items/pages

26 July 2010 at 10:37am
Hi
Im trying to create a front page (the first page, also called HomePage) that contains a selection of teasers (other pages).
Im currently able to select multiple pages from in the CMS, my problem is now how to retrieve these related pages on my frontpage.
I have tried with:
<% control ReferencedPages %>
Title: {$Title}
<% end_control %>
- but this doesnt work.I have also tried in the controller:
$this->ReferencedPages()
..
and
...
foreach($this->ReferencedPages() as $item){
Debug::show($item);
}
- but also here no luck!So right now Im pretty much all out of ideas.
I have pasted the models (excerpt) below.
Thanks!
class HomePage extends Page {
public static $has_many = array(
"ReferencedPages" => 'SiteTree'
);
...
$fields->addFieldToTab("Root.Content.Main", new TreeMultiselectField("ReferencedPages", "Choose page to show", "SiteTree"));class Page extends SiteTree {
public static $has_one = array(
'HomePage' => 'Page'
);
... -
Re: Multiple referenced items/pages

26 July 2010 at 11:23am
With a has_many relationship it should have created a column on the HomePage table called "HomePageID" check if this is set in your database. If it is a null value then $this->ReferencedPages won't show anything as the HomePageID is not set.
http://doc.silverstripe.org/treemultiselectfield mentions that its designed for managing many_many relations rather than many to one so you could be running into issues because of that.
-
Re: Multiple referenced items/pages

26 July 2010 at 7:56pm
Hi
Thanks for your reply!
Is there another field for has_many relationships I should use insted?
Or should I just create it as a many_many and then just use is as a has_many? My thoughts were just that a has_many is simpler than a many_many.I have tried with a has_one, and that worked out for me.
Thanks
-
Re: Multiple referenced items/pages

27 July 2010 at 4:35am
Hi Willr
The HomePageID is created on the Page table and not the HomePage table. But I suppose this is correct.
The HomePageID is set (for the ones that I have chosen via the interface) correctly.
So everything looks ok.But I still can't get anything out in my template or in the controller code.
<% if ReferencedPages %>
testing...
<% end_if %>
... doesnt workDebug::show($this->ReferencedPages());
shows:
ComponentSet
Type: 1-to-many
Size: 0Have anyone tried this before?
Thanks!
-
Re: Multiple referenced items/pages

29 July 2010 at 2:15am
Can anyone confirm that the HomePageID is created on the Page table and not the HomePage table. So I at least know that the data is correct?
Thanks
-
Re: Multiple referenced items/pages

29 July 2010 at 11:10am
Sorry neros3, that was a typo in my orignal post. Yes it should be on the Page table.
| 845 Views | ||
|
Page:
1
|
Go to Top |


