Closed (fixed)
Project:
Content Templates (Contemplate)
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
26 Apr 2010 at 05:53 UTC
Updated:
12 May 2010 at 14:00 UTC
Hello, I've these warnings on my node type contemplate page and the page of my content type.
warning: Invalid argument supplied for foreach() in /home/pariscin/www/sites/all/modules/contemplate/contemplate.module(833) : eval()'d code on line 38.
warning: Invalid argument supplied for foreach() in /home/pariscin/www/sites/all/modules/contemplate/contemplate.module(833) : eval()'d code on line 60.
It's because I'm using this code. If I'm using only one field. I've only one warnng.
<?php
$puntuacion = "";
$i = 0;
$max = count($field_xxx);
foreach ($field_xxx as $item) {
$puntuacion = (++$i < $max) ? " - " : $puntuacion = "";
if($node->field_xxx[0]['view']!="")
print $item['view'].''.$puntuacion.' ';
};
?>
<?php
$puntuacion = "";
$i = 0;
$max = count($field_yyy);
foreach ($field_yyys as $item) {
$puntuacion = (++$i < $max) ? " | " : $puntuacion = "";
print $item['view'].''.$puntuacion.' ';
};
?>
The weird thing is that I'm using this code in another node type with contemplate too and all is workinf fine. No warnings.
It's why is a bug report issue.
Anybody has an idea to remove the warnings?
Thanks
Comments
Comment #1
junro commentedForgot to say I have the warnings only with nodes where field_xxx and field_yyy have no values.
Comment #2
montaldipa commentedYou should be able to type cast $field_xxx and $field_yyy. For example...
foreach ($field_xxx as $item) {...becomes...
foreach ((array)$field_xxx as $item) {This should make the warning go away.
Reference: http://www.php.net/manual/en/language.types.type-juggling.php
Comment #3
junro commentedThanks a lot! I don't have the warnings anymore :)
and thanks for the link! Very usefull ^^