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.

General Questions /

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

Adding additional values to a DataObjectSet


Reply


3 Posts   597 Views

Avatar
ccburns

Community Member, 74 Posts

14 July 2011 at 12:10am

Edited: 14/07/2011 12:11am

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

Avatar
swaiba

Forum Moderator, 1805 Posts

14 July 2011 at 12:24am

Edited: 14/07/2011 12:24am

how about...

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

I do it all the time...

Avatar
ccburns

Community Member, 74 Posts

14 July 2011 at 12:30am

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

I told you I thought it would be simple :)