Jump to:

22977 Posts in 11720 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Adding additional values to a DataObjectSet

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: 470 Views
  • ccburns
    Avatar
    Community Member
    74 Posts

    Adding additional values to a DataObjectSet Link to this post

    Hi All,

    This is probably something really simple that I am missing here.

    Basically building an item management system for frontend users to manage their own items. I have everything working fine except for one thing and I am sure it is something really simple that I just haven't found yet.

    Essentially what I am asking is, is there a way to push a new column of data onto each row in a return DataObjectSet

    So for example if I had FirstName (Colin) and Surname (Burns) and I wanted to create a new column called NickName which I created by the first letter of the FirstName and the Surname (cburns). I want know how to create this column in the logic and push it onto my DataObjectSet.

    N.B: There is probably a way to do this specific example in the template, but that's not what i am looking for. I've deliberately tried to use a really simple example as a demonstration.

    if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
    $SQL_start = (int)$_GET['start'];
    $AllItems = DataObject::get(
    $callerClass = $thisClassName, // enter the Object type (e.g. 'MyPageType')
    $filter = "ItemType = 'want' AND Status = '{$thisStatus}' AND MemberID = '".Member::currentUserID()."'",
    $sort = "Created DESC, Value DESC",
    $join = "",
    $limit = "{$SQL_start}, $itemsPerPage" // enter the number of items per page (int)
    );

    // So I guess in here I would need to loop through the DataObjectSet using two of the fields in it to create a new field and then push it onto the DataObjectSet

    return $this->customise(array('AllItems' => $AllItems))->renderWith('ajax_ListManagement_All');

    Any suggestions would be grand

    Cheers,
    Colin

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Adding additional values to a DataObjectSet Link to this post

    how about...

    if ($AllItems) foreach ($AllItems as $item) {
    $item->NickName = $item->FirstName.'_'.$item->Surname;
    }

    I do it all the time...

  • ccburns
    Avatar
    Community Member
    74 Posts

    Re: Adding additional values to a DataObjectSet Link to this post

    Thanks for the reply, I will give it a shot.

    I told you I thought it would be simple

    470 Views
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.