- Posts: 6
COMMUNITY FORUM
Warning forech()
- Patryk Szczepański
- Topic Author
- Offline
- New Member
Less
More
10 years 8 months ago #123132
by Patryk Szczepański
Warning forech() was created by Patryk Szczepański
Hi, i have Joomla! 3.2.0 and K2 2.6.7.
In category_item.php i add code:
$extrafieldslabels = array();
foreach($this->item->extra_fields as $itemlabel);
{
$extrafieldslabels[$itemlabel->id] = $itemlabel->name;
}
And in code site add:
<?php if ($$itemlabel[1] != "") {echo $itemlabel[1];}?>
but i have error:
Warning: Invalid argument supplied for foreach() in /enklawa/templates/enklawa/html/com_k2/mieszkania/category_item.php on line 17
In item.php it's all ok in the same code.
Why? Please help.
Sorry byt my english is not well.
In category_item.php i add code:
$extrafieldslabels = array();
foreach($this->item->extra_fields as $itemlabel);
{
$extrafieldslabels[$itemlabel->id] = $itemlabel->name;
}
And in code site add:
<?php if ($$itemlabel[1] != "") {echo $itemlabel[1];}?>
but i have error:
Warning: Invalid argument supplied for foreach() in /enklawa/templates/enklawa/html/com_k2/mieszkania/category_item.php on line 17
In item.php it's all ok in the same code.
Why? Please help.
Sorry byt my english is not well.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 8 months ago #123133
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Re: Warning forech()
The $$itemlabel[1] != "" is a typo, you meant $itemlabel, you probably have it correctly in your code as well.
I can also see a trailing semilcolon in the foreach statement. probably another typo as well.
Finally I think this code is not needed.
You can direclty render extrafields or you can implement the check in the default extrafields loop.
I can also see a trailing semilcolon in the foreach statement. probably another typo as well.
Finally I think this code is not needed.
You can direclty render extrafields or you can implement the check in the default extrafields loop.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Patryk Szczepański
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
10 years 8 months ago #123134
by Patryk Szczepański
Replied by Patryk Szczepański on topic Re: Warning forech()
Hi, but error is in the forech loop.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 8 months ago #123135
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Re: Warning forech()
I can see two typos.
Also I told you this code is not really necessary. You can use the default extrafields loop code.
Also I told you this code is not really necessary. You can use the default extrafields loop code.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Patryk Szczepański
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
10 years 8 months ago #123136
by Patryk Szczepański
Replied by Patryk Szczepański on topic Re: Warning forech()
<!-- Call to prepare extra fields -->
<?php
//convertArray to use ids as key
$extrafields = array();
foreach($this->item->extra_fields as $item)
{
$extrafields[$item->id] = $item->value;
}
?>
This is it?
<?php
//convertArray to use ids as key
$extrafields = array();
foreach($this->item->extra_fields as $item)
{
$extrafields[$item->id] = $item->value;
}
?>
This is it?
Please Log in or Create an account to join the conversation.
- Patryk Szczepański
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
10 years 8 months ago #123137
by Patryk Szczepański
Replied by Patryk Szczepański on topic Re: Warning forech()
And in localhost all is ok. Online in my serwer home.pl foreach function not play.
Help.
Help.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 8 months ago #123138
by Krikor Boghossian
This is the default loop in item.php. You can safely adapt this loop to match your needs.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Re: Warning forech()
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if($extraField->value != ''): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<?php if($extraField->type == 'header'): ?>
<h4 class="itemExtraFieldsHeader"><?php echo $extraField->name; ?></h4>
<?php else: ?>
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
<?php endif; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
This is the default loop in item.php. You can safely adapt this loop to match your needs.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Patryk Szczepański
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
10 years 8 months ago #123139
by Patryk Szczepański
Replied by Patryk Szczepański on topic Re: Warning forech()
but. I need only extrafileds value ID 1.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 8 months ago #123140
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Re: Warning forech()
If you only want this then directly render that extrafield.
getk2.org/community/New-to-K2-Ask-here-first/171284-Where-to-edit-K2-after-Item-Fields
getk2.org/community/New-to-K2-Ask-here-first/171284-Where-to-edit-K2-after-Item-Fields
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Patryk Szczepański
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
10 years 8 months ago #123141
by Patryk Szczepański
Replied by Patryk Szczepański on topic Re: Warning forech()
Hi, i add this code:
Log in or Create an account to join the conversation.