10 years ago
3
Topic

Hello dear Seblod team and fellow Seblod users,

I love the potential Seblod adds to Joomla, but sometimes I have trouble getting things done. 

At this moment I'm really struggling to call groupx values in script fields from the Code Pack. I've created a content (item_content_grp) type with 3 fields (field1, field2 and field3) and I've added a groupx field (item_content) in another content type (item) with content type item_content_grp. Now I want the values of field1 and field2 as arrays in a beforeRender field, but I have been struggling to achieve this for many days. 

I get either NULL or array(0) {} as result and the following debug results Notice: Uninitialized string offset, Notice: Trying to get property of non-object and Warning: Illegal string offset 'field1'.

I followed the instructions by Lionel here to create the groupx field (field1, field2 and field3 have no storage and groupx has storage custom | article | item[item_content]).

I installed jdump, but so far it didn't help me. I tried creating array this way with the path to the groupx values I found here:

dump($fields['item_content']);<br> $array1 = array();<br> $c = count($fields['item_content']) - 1;<br> for ($i=0; $i<=$c; $i++) {<br> $array1 = $fields['item_content']->value[$i]['field1']->value<br> }<br> var_dump($array1;

What am I missing? Can anyone help me get this right?

Regards,

Richard

Get a VIP membership
4229 Posts
Kadministrator
10 years ago
0
Level 1

Try dumping $fields first to see what kind of information is there.

10 years ago
1
Level 1

Hi Klas,

Thanks for your response. I was not sure how your suggestion would help me. I tried it, but the dump now contained all content item fields. So I decided to look for more information on the web about mixed objects and arrays. For more clarity I renamed the groupx field to groupx1 in the example below.

At the some point I realised that it I needed to point to the form array and loop through its children, which resulted in this:

$array1 = array();
$c = intval($fields['groupx1']->display -1);//correction for extra field shown by default
for ($i = 0; $i < $c; ++$i) {
   $array1[] = $fields['groupx1']->form[$i]['field1']->value;
}

Which returned:

array (

  [0] => value1

  [1] => value2

  [2] => value3

)

And that was what I was looking for.  So finally I have this problem solved.

Regards,

Richard

10 years ago
0
Level 2

The $c needs no correction so it should be just: $c = intval($fields['groupx1']->display;

Get a VIP membership