Jump to:

23552 Posts in 19349 Topics by 2891 members

General Questions

SilverStripe Forums » General Questions » ajax load - renderWith - DataObjectSet - many_many

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1699 Views
  • Lukin
    Community Member
    42 Posts

    ajax load - renderWith - DataObjectSet - many_many Link to this post


    I have a dropdown field in my frontend and want to load special content via ajax after choosing a Kategorie (category)

    Requesting via Ajax works fine... but I dont' know how to bring my valus I get with the DataObject::get() method to my template control snippet,..

    that's my sql.. it works fine, (i've tested the sql statement in phpmyadmin. It returns several rows of Typ-Table which I connected to the Kategorie (with the ID 6) via an many_many relationship)

             $doSet = DataObject::get(
                $callerClass = "Kategorie",
                $filter = "Kategorie.ID =6",
                $sort="Typ.Bezeichnung ASC",
                //$sort = "ORDER BY SortOrder DESC",
                $join = "LEFT JOIN Kategorie_Typen ON Kategorie_Typen.KategorieID=Kategorie.ID LEFT JOIN Typ ON Kategorie_Typen.TypID=Typ.ID",
                $limit = ""

    now id like to get that DataObject rendered with my Typ-Template
    to use it in its control-tag
    <% control Typ %>
    <% end_control %>

    something like that..:

    return $doSet->renderWidth(array('TypTemplate'));

    this causes two warnings and returns only the empty template:
    1. DataObjectSet::__construct:Passed item #0 is not an object or assoziative array, can't properly iterated on in templates
    2. Unknown class passed as parameters

    How to return my DataObjectSet to my Template and how can I control the data?

    Thanks in advance for any advice


  • Willr
    Forum Moderator
    5511 Posts

    Re: ajax load - renderWith - DataObjectSet - many_many Link to this post

    Try call renderWith on the controller instance and adding your set to that

    return $this->customize(new ArrayData(array('Typ' => $doSet)))->renderWith(array('TypTemplate'));

  • Lukin
    Community Member
    42 Posts

    Re: ajax load - renderWith - DataObjectSet - many_many Link to this post

    Hi Willr

    First it caused an error: method customize does not exist on 'Produkte_Controller'

    so I tried it without the customize method and that works fine now

    $data=new ArrayData(array('Typ' => $doSet));
    return $data->renderWith(array('TypTemplate'));

    Thank s a lot !!

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.