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.

Data Model Questions /

How to access ArrayData values by another function ???


Reply


3 Posts   1538 Views

Avatar
nakashu

Community Member, 24 Posts

18 June 2010 at 11:30am

Probably very silly question but can get it done ...

function test() {
   $values = new ArrayData(array(
      'd1' => 'somedata',
      'd2' => 'moredata',
   ));
return $values;
}

function stuff() {
   $a = $this->test();
   $b = $a[d1].'added';
   return $b;
}

accessing data in arraydata as in regular array drops error?
thank for help ..

Avatar
Willr

Forum Moderator, 5513 Posts

18 June 2010 at 4:02pm

Well because you have a ArrayData object read the ArrayData API for what you can call on that object. getField($fieldname). Sounds like that you want to do. I think you can also use magic vars like $a->d1 to get the d1 or $a->getField('d1'); is the long option.

Ref: http://api.silverstripe.org/2.4/sapphire/view/ArrayData.html

Avatar
nakashu

Community Member, 24 Posts

18 June 2010 at 9:21pm

Thank Willr - works nicely :)

the things is I tried the getField but like this: $x = getField('d1',$a), yeah me stupid cant read API properly :)
thanks again .. have a nice day.