21301 Posts in 5736 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1469 Views |
-
nested controls: get values from parent

6 October 2009 at 10:34am Last edited: 6 October 2009 10:35am
Hi, i am trying to loop through one menu control [Menu(3)]. Within the loop i nested a custom control.
the result shoud look like this:
- item 1.$MenuTitle
item a. (item 1 $Top.Link)
item b. (item 1 $Top.Link)
item c. (item 1 $Top.Link)
- item 2.$MenuTitle
item a. (item 2 $Top.Link)
item b. (item 2 $Top.Link)
item c. (item 2 $Top.Link)
- item 3.$MenuTitle
item a. (item 3 $Top.Link)
item b. (item 3 $Top.Link)
item c. (item 3 $Top.Link)
- item 4.$MenuTitle
item a. (item 4 $Top.Link)
item b. (item 4 $Top.Link)
item c. (item 4 $Top.Link)The Problem is, that you It will NOT return the additionally joined data (http://doc.silverstripe.org/doku.php?id=datamodel#joining)
How can i get the right Data?
P.S.There is another small thing: if you use s.t. like: $Top.Link/show/$ID you will have a double slash, because $Top.Link already contains one "/" (gesundheitswesen//show/6). How can i get rid of it?
Greetings, Carsten.
Template:
<div id="banner">
<div class="banner_top"> </div>
<div class="banner_inner">
<ul class="menu">
<% control Menu(3) %>
<li class="sublevel1">$MenuTitle
<ul>
<% control getFirmenforBanner %>
<li class="sublevel2">
<a href="$Top.Link/show/$ID">$Firmenname $URLSegment</a>
</li>
<% end_control %>
</li>
</ul>
</li>
<% end_control %>
</ul>
</div>
<div class="banner_end"> </div>
</div>Page.php (model):
function getFirmenforBanner() {
// Tabelle + Where + Sort + JOIN + LIMIT
$firmen = DataObject::get("Stammdaten", "", "Stammdaten.Firmenname", "", "");
//Debug::show($firmen);
//die;
return $firmen;
} -
Re: nested controls: get values from parent

6 October 2009 at 3:33pm
You were close, just had to make it to SQL Query per the instructions in the link you posted
http://doc.silverstripe.org/doku.php?id=sqlquery&s=sqlquery#transforming_a_result_to_dataobjectset
-
Re: nested controls: get values from parent

6 October 2009 at 4:51pm
And for $Top.Link/show/$ID you would just remove the / before the show - {$Top.Link}show/$ID
-
Re: nested controls: get values from parent

6 October 2009 at 10:00pm
Thanks Dalesaurus, thanks Willr,
i got it all working. If you read the docs carefully you can nearly solve every problem. To get all Data i had to build a foreach-loop.
Here is the code from my controller:
function getFirmenforBanner() {
$sqlQuery = new SQLQuery();
$sqlQuery->select = array(
'Firmenname AS Firmenname',
'Bereich AS Bereich',
'SiteTree.URLSegment AS URLSegment',
'SiteTree.Title AS Title',
'Stammdaten.ClassName AS ClassName',
'Stammdaten.ClassName AS RecordClassName',
'Stammdaten.ID AS ID'
);
$sqlQuery->from = array(
"Stammdaten",
"LEFT JOIN SiteTree ON Stammdaten.Bereich = SiteTree.ID"
);
$sqlQuery->where = array(
"SiteTree.ShowInMenus = 1 AND Bereich = ".$this->ID.""
);
$result = $sqlQuery->execute();
$firmen = new DataObjectSet();
foreach($result as $row) {
$firmen->push(new ArrayData($row));
}
return $firmen;
}
| 1469 Views | ||
|
Page:
1
|
Go to Top |



