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 |
Jump to:
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
$static works per field and allows to reuse data per row for that field.
#2
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
What if the help text said something like:
$static: can be used to store reusable data per row for this field only.
#4
You can manipulate
$thisdirectly, which is an object of typeviews_customfield_handler_field_phpcode, derived fromviews_handler_field. So you can set$this->img_pathinfield #1 and read it in field #2row #1 and read it in row #2 (sorry for the confusion my mistake has caused).#5
Thanks...I'll try that...don't know why that didn't occur to me.
#6
#7
Automatically closed -- issue fixed for 2 weeks with no activity.
#8
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
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
@mpaler: You should be able to. The best way to know is to try :-)
#11
Not getting any errors and values are returned as expected. So yes, I believe it works.
Thanks.
#12
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
setting to active.
#14
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
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
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
#18
Neat, never noticed that. Learning is fun!
#19
Automatically closed -- issue fixed for 2 weeks with no activity.