Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » 'getviewer' does not exist on 'DataObjectSet'

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

Page: 1
Go to End
Author Topic: 866 Views
  • LisaB
    Community Member
    28 Posts

    'getviewer' does not exist on 'DataObjectSet' Link to this post

    Hi all,

    I have a form consisting of several dropdowns which allows users to filter a list of dataobjects (habits) that they want to see by various fields (deadline, assigned staffmember, priority). This works okay in the page.

    The form's action is a function that uses the dropdown selections to create a filter statement for a dataobject::get. So far so good - I can see from my debug statements that the appropriate data object set is got.

    I use a foreach loop to iterate over this set, adding some additional bits to each record via an array which seems to work okay. This is then written back into a data object set to be returned and displayed (on the same page as the original form). But I get an error:

    'getviewer' does not exist on 'DataObjectSet'

    Can anyone help me out with this? Although I have other forms doing a similar thing, I cannot get this to display the list of data objects I am returning. My code is here: http://www.sspaste.com/paste/show/4dd4134046e3c

    As always any help much appreciated.

  • Plato
    Community Member
    26 Posts

    Re: 'getviewer' does not exist on 'DataObjectSet' Link to this post

    Hi Lisa,

    As I explained on the IRC channel, getViewer is on the controller. You're trying to render a set as a page, to which it cannot do. You need to return a controller, which is usually $this.

    In shorthand you can simply return an array to customise the template variables available to SSViewer on this controller, so you'll just need to encapsulate your DataObjectSet as such:

    return array('HabitSet'=>$habitDisplaySet);

    In your templates you can use $habitFilterForm to render the form, then <% control HabitSet %> to process the results.

    You can just do this in the plain template (as HabitSet won't exist on normal render and be ignored), or you can create a template WhateverYourClassNameIs_filterhabits.ss (ClassName_action.ss) if you want to jazz things up once you have some results.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.