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.

Archive

Our old forums are still available as a read-only archive.

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

Control in a Control


Reply

2 Posts   1214 Views

Avatar
UncleCheese

25 February 2008 at 5:42am 4085 Posts

I have a ProductionHolder page that uses <% control Children %> to loop through all its Production objects. Each Production has a has_many with Characters. I need to loop through Characters inside of that loop. How do I do that?

Here's what I have:

<% control Children %>
$Title
$Date
$Content
<% control character %>
$name
<% end_control %>
<% end_control %>

This looks like it's on the right track, but it's throwing a database error. It's filtering by the "ParentID" field, which doesn't exist, on the Character object when it should be filtering based on the ProductionID field.

Why ParentID? What did I do wrong?

Avatar
saimo

26 February 2008 at 5:25am Community Member, 67 Posts

You should create new functions in the Controller class:

function Characters() {
   return DataObject::get("Character", "ProductionID = {$this->ID}", "", "",);
}

That should get the Characters. The third argument is for a SQL sort fragment eg. "Created DESC" if you need that. Replace Children with Characters in your inner control.

This is because Children returns the pages that are children of the current page in the CMS.

If it doesn't work then please post your Production.php file.