By youresorandom.com on
How can you check if an object of type stdClass is empty in a view?
(I try this because I want to disable a button, like Read More... when there is no text to read more..)
I've tried:
<?php
if (is_null($fields['body']) {
echo "empty";
}else{
echo "not empty";
}
?>
and
<?php
$mystring= (string)$fields['body'];
if ((strlen($fields['body'])>0) {
echo "not empty";
}else{
echo "empty";
}
?>
In the first case, I always get not empty, even though there is no text in the object..
The error showing when I try converting to string is
Object of class stdClass could not be converted to string
Comments
arrows
If you see a standard class notation, use an arrow not square brackets when stepping down through arrays
e.g. $mystring= (string)$fields->body; or something like that?
thanks, works perfect..
thanks,
works perfect..