Cannot reference $static to pass data from one phpcode field to another

drkdn - July 14, 2009 - 16:50
Project:Views Custom Field
Version:6.x-1.0
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

In a phpcode field, I am running an algorithm that finds a particular image, and then outputs a thumbnail of that image. The next phpcode field outputs a larger version of that image, but I do not want to run the whole algorithm again to find the original image. Using $static->img_path = $img_path or $this->static->img_path = $img_path in the first field does not make the image path available to the second field. Doing it as an array does not work either, which shouldn't matter anyway. What am I missing?

#1

casey - July 14, 2009 - 17:06

$static works per field and allows to reuse data per row for that field.

#2

drkdn - July 14, 2009 - 18:22

Ahhh...ok...the documentation/help could be a little more clear to that end. Is there another way to do something like this? I can't seem to run the algorithm in an excluded field to be referenced by subsequent fields.

#3

drkdn - July 14, 2009 - 18:26

What if the help text said something like:

$static: can be used to store reusable data per row for this field only.

#4

kratib - November 16, 2009 - 23:20

You can manipulate $this directly, which is an object of type views_customfield_handler_field_phpcode, derived from views_handler_field. So you can set $this->img_path in field #1 and read it in field #2 row #1 and read it in row #2 (sorry for the confusion my mistake has caused).

#5

drkdn - July 27, 2009 - 15:29

Thanks...I'll try that...don't know why that didn't occur to me.

#6

casey - July 29, 2009 - 08:29
Status:active» fixed

#7

System Message - August 12, 2009 - 08:30
Status:fixed» closed

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

#8

mpaler - November 16, 2009 - 18:21

Can I make $static into an array or object so I can store more than one bit of data per row?

eg:

  $static['mw'] = ($_GET['mw'] * 1000);

Thanks for the great module.

#9

mpaler - November 16, 2009 - 18:22
Status:closed» active

Can I make $static into an array or object so I can store more than one bit of data per row?

eg:

  $static['mw'] = ($_GET['mw'] * 1000);

Thanks for the great module.

#10

kratib - November 16, 2009 - 19:07

@mpaler: You should be able to. The best way to know is to try :-)

#11

mpaler - November 16, 2009 - 21:07
Status:active» closed

Not getting any errors and values are returned as expected. So yes, I believe it works.

Thanks.

#12

mpaler - November 16, 2009 - 22:48

I'm back.

I'm trying to perform the task described in #4 above where you set the value of something in one custom php field so it's accessible in another php field on the same row.

In field one I do:

$this->test = "5";

in field 2 I do:
print $this->test;

and nothing prints.

Any thoughts? Am I understanding this incorrectly?

Mike

#13

mpaler - November 16, 2009 - 22:48
Status:closed» active

setting to active.

#14

kratib - November 16, 2009 - 23:22

I re-read my earlier comment and I was mistaken. Very sorry about that. To reiterate, you cannot share values *across fields*, but you can share values *across rows* of the same field. If you want to achieve the same across fields, the immediate solution that comes to mind is using $_SESSION.

#15

bfr - November 17, 2009 - 15:39

I dont know if it's recommended, but i use $data->something to share data between fields.
However, that does not work across rows, so you will have to first use $data->myvar to pass it to another field and then $static->myvar=$data->myvar to pass it to the next row.

Other way is to use set_var() to store the data in to database and then get_var() to retrieve it, but that fills the variable table which is not very good solution
if you will be writing lots of stuff to there.

Third way is ofcourse to make new database table for your data and use normal mysql functions to write and read.

#16

mpaler - November 17, 2009 - 19:16

Thanks.

I'm able to reference custom fields across a row by doing a print_r($data); in a field and looking for the referenced custom field. They look like the following:

$data->customfield_phpcode_5;
$data->customfield_phpcode_6;

etc.

Thanks,
Mike

#17

kratib - November 17, 2009 - 19:29
Status:active» fixed

#18

bfr - November 18, 2009 - 09:22

Neat, never noticed that. Learning is fun!

#19

System Message - December 2, 2009 - 09:30
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.