I'm trying to print flags related to row of my view using Views PHP
print flag_create_link('myflag', $row->nid);
No result. Any idea?


smouhaer’s picture

Component: Code » Documentation
Assigned: Unassigned » smouhaer
Issue tags: +Flag, +views php

try this method

$myflagl=flag_create_link('myflag', $row->nid);
print $myflag;

Grzegorz Zbiński’s picture

Status: Active » Fixed

I know, why it wasn't rendered.

I've put:

print flag_create_link('myflag', $row->nid);

into wrong place...

It should be in Output code (and I've put it in Value code, which was wrong). Now it is working fantastic!

I've checked dblog where goes things like those:
Notice: Undefined variable: flag in __lambda_func() (line 1 from .../sites/all/modules/views_php/plugins/views/views_php_handler_field.inc(131) : runtime-created function).
Notice: Undefined property: stdClass::$views_php_15 in views_php_handler_field->render() (line 223 from .../sites/all/modules/views_php/plugins/views/views_php_handler_field.inc).

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

fehin’s picture

Status: Closed (fixed) » Active

How do I print a flag link for users and use a user reference field instead.
I have tried different method. The last one I tried was

$requester_firstd = $data->_field_data['nid']['entity']->field_requester_user['und'][0]['value'];
print flag_create_link('date_showup', $requester_firstd); 


$requester_firstd = $data->_field_data['nid']['entity']->field_requester_user['und'][0]['uid'];
print flag_create_link('date_showup', $requester_firstd); 

but it didn't work.

I got Notice: Undefined index: value in __lambda_func() and Notice: Undefined index: uid in __lambda_func()

fehin’s picture

My solution:

global $user;

$requester_user = db_query("SELECT field_requester_user_target_id FROM {field_data_field_requester_user} WHERE entity_id IN ($row->nid)")->fetchField();

$requestee_user = db_query("SELECT field_requestee_user_target_id FROM {field_data_field_requestee_user} WHERE entity_id IN ($row->nid)")->fetchField();

$current_user = $user->uid;

if($current_user == $requester_user)
{print flag_create_link('date_showup', $requestee_user_1st);}
else if($current_user == $requestee_user)
{print flag_create_link('date_showup', $requester_user);}
bharata’s picture

I'm trying to follow in your footsteps Grzegorz, and would like to ask you two questions.

Am I correct that I must leave out the begining and ending PHP tags?

Also, does it make a differece if I use " or ' ? 'myflag' vs "myflag"?

Just wanting ot be sure I am doing it correctly. It's not working anyway but I could rule syntax out if I'm at least entering the code in correctly.

I am still seeing:

Notice: Undefined property: stdClass::$views_php_2 in views_php_handler_field->render() (line 223 from .../sites/all/modules/views_php/plugins/views/views_php_handler_field.inc).


bharata’s picture

OK. I solved my problem. Grzegorz bold faced the answer. Others on other threads have mentioned this as well. But regardless, I did not actually understand because at the top of the entry screen for the global PHP field it says,

"Use PHP code to construct the output of a field."

I assumed that meant I was doing the right thing. Wrong! You must scroll down. There are TWO fields.
Enter your code into the SECOND one. And DO use PHP tags.

marcoka’s picture

Issue summary: View changes

deleted my comment. wrong statement.