Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi, I use a PHP field for print the first image of the body.
I write this code:
<?php
$vid = db_query("SELECT vid FROM {node} WHERE nid=:nid", array(':nid'=>$data->nid) )->fetchField();
$node = node_load($data->nid,$vid,TRUE);
if( $imgs = explode('[img', $node->body['es']['0']['value']) ){
$cont=1;
while( !$imagen and $cont<sizeof($imgs) ){
$partes = explode('[/img]', $imgs[$cont]);
$principio = explode(']', $partes[0]);
if( !(strstr($principio[1], 'smilies')) )
$imagen = $principio[1];
else $cont++;
}
}
if( isset($imagen) )
print $imagen;
?>
The code works but give this errors:
* Notice: Undefined variable: imagen en __lambda_func() (línea 8 de C:\xampp\htdocs\drupal7\sites\all\modules\views_php\plugins\views\views_php_handler_field.inc(196) : runtime-created function).
* Notice: Undefined variable: imagen en __lambda_func() (línea 8 de C:\xampp\htdocs\drupal7\sites\all\modules\views_php\plugins\views\views_php_handler_field.inc(196) : runtime-created function).
Comments
Comment #1
meatbag CreditAttribution: meatbag commentedI try to use the following code
But i get the following errors:
# Notice: Trying to get property of non-object in __lambda_func() (line 1 of D:\xampplite\htdocs\drupal\sites\all\modules\views_php\plugins\views\views_php_handler_field.inc(132) : runtime-created function).
# Notice: Undefined property: stdClass::$_field_data in __lambda_func() (line 1 of D:\xampplite\htdocs\drupal\sites\all\modules\views_php\plugins\views\views_php_handler_field.inc(132) : runtime-created function).
Comment #2
casey CreditAttribution: casey commented#TS:
You check for a variable that isn't defined yet in the while condition.
Should be
Comment #3
casey CreditAttribution: casey commented#1
What do you get if you use the following output code:
Comment #4
meatbag CreditAttribution: meatbag commentedIf i use the following code
instead of
I can get the correct result.
Here's the $data output
Comment #5
casey CreditAttribution: casey commentedOw wait a sec... the field data is of course not yet added tot the result set when the value code is run. I'll see what I can do.
Comment #6
marta_yo CreditAttribution: marta_yo commented#2 works!!
thank you very much
Comment #7
casey CreditAttribution: casey commentedFor field data keep an eye on #1061388: Add field data to the result set.