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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Nested controls from model admin


4 Posts   1047 Views


9 September 2009 at 8:06pm Community Member, 187 Posts

I am a bit confused and unsure if I have made an error in setting up a model admin for an faq. I think model admin is great and the faq seemed ideal for administering it but when I come to display if I wonder if I have the wrong end of the stick and shouldn't have used modeladmin

In more detail I have an faqadmin which enables the administrator to create frequent questions and answers and then to categorise them.

<? class FaqAdmin extends ModelAdmin {

protected static $managed_models = array(

static $url_segment = 'faq'; // will be linked as /admin/faq
static $menu_title = 'FAQ Admin';


This is all working well my problem comes when I want to display the faq grouped by category. I can pull back the data

function getFaqCategory() {
    return DataObject::get("FaqCategory", "", "", "", "");
function getFaq() {
    $category = DataObject::get_one("FaqCategory");
    return ($category) ? DataObject::get("Faq", "$category.ID", "DisplayOrder ASC", "", "") : 'false';

but how do I nest the getFaq inside the getFaqCategory? What I have so far is:
<% control getFaqCategory %>
<% control getFaq %>
      <p class="orange">Q: $Question</p>
   <% end_control %>
<% end_control %>

Do I need to nest the function instead? If so, how?

Many thanks



10 September 2009 at 2:24am (Last edited: 10 September 2009 2:25am), 4085 Posts


class Faq extends DataObject
static $has_one = array ('FaqCategory' => 'FaqCategory');

static $db = array (.....);
// etc...



class FaqCategory extends DataObject
static $has_many = array ('Faqs' => 'Faq');

static $db = array (....);



MyFaqPage.php (e.g.)

class MyFaqPage extends Page
function FaqCategories()
return DataObject::get("FaqCategory");

<% control FaqCategories %>
<% if Faqs %>
<% control Faqs %>
<% end_control %>
<% else %>
No faqs.
<% end_if %>
<% end_control %>


10 September 2009 at 2:26am 4085 Posts

Also, avoid using getXXX() methods on your template to keep a distinction between template methods and controller/model methods.

<% control getFaq %>


<% control Faq %>


12 September 2009 at 10:31am Community Member, 187 Posts

Thanks Uncle Cheese. This worked well and I think I am starting to understand it all.