COMMUNITY FORUM
[solved] Extra Field array broken in new version?
- Aaron
- Topic Author
- Offline
- Premium Member
Less
More
12 years 5 months ago - 12 years 5 months ago #65623
by Aaron
[solved] Extra Field array broken in new version? was created by Aaron
I am trying to troubleshoot but I have run into a brick wall...
Below is the code that DOES work in the previous version of K2 but 2.5.6 doesn't like it :(
Aaron :)
Below is the code that DOES work in the previous version of K2 but 2.5.6 doesn't like it :(
"Warning: Invalid argument supplied for foreach() in /xxxxxxxxxxx/html/components/com_k2/templates/xxxxxx/category_item.php on line 21
Warning: Invalid argument supplied for foreach() in /xxxxxxxxxxx/html/components/com_k2/templates/xxxxxx/category_item.php on line 30"
Line 21 is:
foreach($this->item->extra_fields as $itemid)
Line 30 is:
foreach($this->item->extra_fields as $itemlabel)
Any help would be appreciated? Did the db names change?
Aaron :)
Please Log in or Create an account to join the conversation.
- matthew turner
- Offline
- Senior Member
Less
More
- Posts: 66
12 years 5 months ago - 12 years 5 months ago #65624
by matthew turner
Replied by matthew turner on topic Re: Extra Field array broken in new version?
Hi,
I use a similar for each routine when I use the extra fields - far more useful than the default list of extra fields!
I found that moving the for each code inside the "if this item params get itemExtrafields - endif" and then moving this to the top of the template over ride file stopped this error for me - I moved it near the top as I use extra fields for sub titles galleries, plugins etc all the way through my templates!
Heres the code I use (on k2.5 - k2.6, J1.5-J2.5) it allocates just the values to a variable which can then be echo'd wherever you need in the template - can be extended to include extrafield title/name if required:
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
<?php foreach ($this->item->extra_fields as $key=>$extraField):
switch($extraField->id) {
case 1:
$ResearchTitle = $extraField->value;
break;
case 2:
$ResearchBlock1 = $extraField->value;
break;
case 3:
$CourseVenueTitle = $extraField->value;
break;
case 4:
$CourseMapLinkText = $extraField->value;
break;
case 5:
$CoursePrice = $extraField->value;
break;
case 6:
$CourseVenueDetails = $extraField->value;
break;
}
endforeach;
?>
<?php endif; ?>
<?php if(!empty($ResearchTitle)): ?>
<span class="ResearchTitle"><?php echo $ResearchTitle; ?></span>
<?php endif;?>
Hope this makes sense/helps!
Regards
Mat
I use a similar for each routine when I use the extra fields - far more useful than the default list of extra fields!
I found that moving the for each code inside the "if this item params get itemExtrafields - endif" and then moving this to the top of the template over ride file stopped this error for me - I moved it near the top as I use extra fields for sub titles galleries, plugins etc all the way through my templates!
Heres the code I use (on k2.5 - k2.6, J1.5-J2.5) it allocates just the values to a variable which can then be echo'd wherever you need in the template - can be extended to include extrafield title/name if required:
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
<?php foreach ($this->item->extra_fields as $key=>$extraField):
switch($extraField->id) {
case 1:
$ResearchTitle = $extraField->value;
break;
case 2:
$ResearchBlock1 = $extraField->value;
break;
case 3:
$CourseVenueTitle = $extraField->value;
break;
case 4:
$CourseMapLinkText = $extraField->value;
break;
case 5:
$CoursePrice = $extraField->value;
break;
case 6:
$CourseVenueDetails = $extraField->value;
break;
}
endforeach;
?>
<?php endif; ?>
<?php if(!empty($ResearchTitle)): ?>
<span class="ResearchTitle"><?php echo $ResearchTitle; ?></span>
<?php endif;?>
Hope this makes sense/helps!
Regards
Mat
Please Log in or Create an account to join the conversation.
- Aaron
- Topic Author
- Offline
- Premium Member
12 years 5 months ago - 12 years 5 months ago #65625
by Aaron
Aaron :)
Replied by Aaron on topic Re: Extra Field array broken in new version?
I like where you went with this... can you explain the "cases" a little more? Do they represent the different extra fields?
BTW, still getting an error.. it just DOES NOT like the foreach... sigh.. I even tried it right in the default template to make sure it wasn't something else in my code.. :S
Isn't there a way just to pull out the references to each without a for each? Seems a little redundant to have to create an array when the fields already exist..
BTW, still getting an error.. it just DOES NOT like the foreach... sigh.. I even tried it right in the default template to make sure it wasn't something else in my code.. :S
Isn't there a way just to pull out the references to each without a for each? Seems a little redundant to have to create an array when the fields already exist..
Aaron :)
Please Log in or Create an account to join the conversation.
- Aaron
- Topic Author
- Offline
- Premium Member
12 years 5 months ago #65626
by Aaron
Aaron :)
Replied by Aaron on topic Re: Extra Field array broken in new version?
Is there a way I can get a list of the db call/fields that K2 uses? Is there a command I would use in the code to list them? Sorry.. I am a bit weak with PHP :(
Aaron :)
Please Log in or Create an account to join the conversation.
- Aaron
- Topic Author
- Offline
- Premium Member
12 years 5 months ago #65627
by Aaron
Replied by Aaron on topic Re: Extra Field array broken in new version?
I have been researching this issue all afternoon... I have to go live with the site by May 4th and I don't have the ability currently to separate the extra fields.... so any advice would be highly appreciated.
I created this code to check that the array exists:
I created this code to check that the array exists:
Aaron :)
Please Log in or Create an account to join the conversation.
- Aaron
- Topic Author
- Offline
- Premium Member
12 years 5 months ago #65628
by Aaron
Aaron :)
Replied by Aaron on topic Re: Extra Field array broken in new version?
It's official... I have been working too hard... When I upgraded, at some point, "show extra fields" was turned off.... sigh.. Seems to work now :)
Aaron :)
Please Log in or Create an account to join the conversation.
- matthew turner
- Offline
- Senior Member
Less
More
- Posts: 66
12 years 5 months ago #65629
by matthew turner
Replied by matthew turner on topic Re: Extra Field array broken in new version?
Hi Aaron,
Yes - you need to step away from the computer ! I find a little "distance" helps to clarify things !
The cases routine is great as the variables are derived from the Extrafield ID number (which cannot be changed easily) and so are "easier" to remember/use through out the template....
Glad to hear you found it was an "easier" if not so obvious fix (after having already tried various code changes - I hear Homer Simpson "Doh!")
Regards
Mat
Yes - you need to step away from the computer ! I find a little "distance" helps to clarify things !
The cases routine is great as the variables are derived from the Extrafield ID number (which cannot be changed easily) and so are "easier" to remember/use through out the template....
Glad to hear you found it was an "easier" if not so obvious fix (after having already tried various code changes - I hear Homer Simpson "Doh!")
Regards
Mat
Please Log in or Create an account to join the conversation.