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?
Comments
Comment #1
casey commented$static works per field and allows to reuse data per row for that field.
Comment #2
derekdunagan commentedAhhh...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.
Comment #3
derekdunagan commentedWhat if the help text said something like:
$static: can be used to store reusable data per row for this field only.
Comment #4
infojunkieYou 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).Comment #5
derekdunagan commentedThanks...I'll try that...don't know why that didn't occur to me.
Comment #6
casey commentedComment #8
mpaler commentedCan I make $static into an array or object so I can store more than one bit of data per row?
eg:
Thanks for the great module.
Comment #9
mpaler commentedCan I make $static into an array or object so I can store more than one bit of data per row?
eg:
Thanks for the great module.
Comment #10
infojunkie@mpaler: You should be able to. The best way to know is to try :-)
Comment #11
mpaler commentedNot getting any errors and values are returned as expected. So yes, I believe it works.
Thanks.
Comment #12
mpaler commentedI'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:
in field 2 I do:
and nothing prints.
Any thoughts? Am I understanding this incorrectly?
Mike
Comment #13
mpaler commentedsetting to active.
Comment #14
infojunkieI 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.Comment #15
bfr commentedI 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.
Comment #16
mpaler commentedThanks.
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
Comment #17
infojunkieComment #18
bfr commentedNeat, never noticed that. Learning is fun!
Comment #20
murzI didn't see my customfield fields via print_r($data); Where can be the problem?
Comment #21
arski commentedI don't see them in there either tbh :(
Comment #23
mpaler commentedPut it right in the php customfield itself. If you have devel enabled, you can do dpm($data); as well.
Comment #24
bfr commentedRemember that in views the data is available only from preceeding fields. So if you have your fields like this:
1. customfield 1
2. customfield 2
3. customfield 3: print_r($data);
4. customfield 4
5. customfield 5
You will see the data only from fields 1-3(well, did not actually test with customfield, but that's how it is atleast with all the other fields).
Comment #25
_vid commented@drkdn
I thought the same thing you did. The note at the bottom of each Customfield: PHP code field says: "$static: can be used to store reusable data per row." but as casey points out it's only available in that field.
When you want to pass data from one field to another across the row then append the data object like so:
$data->img_path = $img_path;$data->img_path is then available to all other Customfield: PHP code fields in that row.
Comment #26
Joel MMCC commentedOkay, so, it’s been almost a decade since this issue was started, ¾ decade since the last comment (@_vid’s #25 itself referencing @casey’s #1[!]) remarked specifically on how misleading the “help” text for the
$staticvariable is to claim that it’s per row instead of per field. Since then, the PHP part of Views Customfield has been spun off into a new project, Views PHP and has even had a 7.x-2.x branch since then.Guess what the “help” text still says even in the latest -dev release of Views PHP, after all this time, and after the misleading nature of it has been known this long?