- Posts: 50
COMMUNITY FORUM
Get Extrafields from external page
- Andrea Vigato
-
Topic Author
- Offline
- Senior Member
Less
More
13 years 10 months ago #97621
by Andrea Vigato
Get Extrafields from external page was created by Andrea Vigato
Hi all,
i have a problem while trying to get extrafields information of an item in an external page of K2.
I'm using jxfinder to search k2 item, in the search-result page i want to add extrainfo of the item.
I've see that k2 use this one:
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
### code ###
<?php endforeach; ?>
Now, i have the id of the item but sure cannot use $this->item, is there a way to get extrafield of an item starting by the id?
Thanks,
Andrea
i have a problem while trying to get extrafields information of an item in an external page of K2.
I'm using jxfinder to search k2 item, in the search-result page i want to add extrainfo of the item.
I've see that k2 use this one:
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
### code ###
<?php endforeach; ?>
Now, i have the id of the item but sure cannot use $this->item, is there a way to get extrafield of an item starting by the id?
Thanks,
Andrea
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
Less
More
- Posts: 3722
13 years 10 months ago #97622
by william white
Replied by william white on topic Get Extrafields from external page
Not sure what you mean by external page.
I create an array inside item or category_item.php to get at the xtra fields - may help
$custom = $this->item->extra_fields;and then addressing extra fields for the item likeecho $custom[1]->value;
I create an array inside item or category_item.php to get at the xtra fields - may help
$custom = $this->item->extra_fields;and then addressing extra fields for the item likeecho $custom[1]->value;
Please Log in or Create an account to join the conversation.
- Andrea Vigato
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 50
13 years 10 months ago #97623
by Andrea Vigato
Replied by Andrea Vigato on topic Get Extrafields from external page
yes, but i'm requesting item extrafield external from k2, actually inside jxfinder search result, where i want to display the requested item and append image and extrafield of the item from k2.
So the $this->item->extra_fields it's not ok....i "managed" to get the extra_fields of the item by SQL, then explode and trim the string while not reach the values. I hoped there was an easy way :)
So the $this->item->extra_fields it's not ok....i "managed" to get the extra_fields of the item by SQL, then explode and trim the string while not reach the values. I hoped there was an easy way :)
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
Less
More
- Posts: 3722
13 years 10 months ago #97624
by william white
Replied by william white on topic Get Extrafields from external page
Due to the way k2 puts xtra fields in one sql field and stores images with a generated name, i dont think there is going to be an easy way, have to recreate the code that k2 uses to dig them out and use it just after you have gathered your search results in external program - doable, but not easy:(
Please Log in or Create an account to join the conversation.
- Andrea Vigato
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 50
13 years 10 months ago #97625
by Andrea Vigato
Replied by Andrea Vigato on topic Get Extrafields from external page
infact as i said i managed to get the extra_fields column of a certain item ID and save the result in a var, the result is something like:
[{"id":"a","value":"b"},{"id":"c","value":"d"},{"id":"e","value":"f"}] etc etc
After that i exploded, trimmed and used a FOR to get the values.
If someone need help in all of this just contact me...so SOLVED.
Anyway thanks William for the replies :)
[{"id":"a","value":"b"},{"id":"c","value":"d"},{"id":"e","value":"f"}] etc etc
After that i exploded, trimmed and used a FOR to get the values.
If someone need help in all of this just contact me...so SOLVED.
Anyway thanks William for the replies :)
Please Log in or Create an account to join the conversation.
- soport
-
- Offline
- New Member
Less
More
- Posts: 2
13 years 10 months ago #97626
by soport
Replied by soport on topic Get Extrafields from external page
Hello, I have the same problem. I´m trying to call the values of the extrafields in a module ( The module is Captify content).In the helper. php of the module i declare ( following instructions from other posts):$item->prueba = $item->extra_fields;
And in the default.php of the module i call the extrafields with this;<?php echo $item->prueba;?>The result is like yours:[{"id":"a","value":"b"},{"id":"c","value":"d"},{"id":"e","value":"f"}] etc etcBut now i don´t know how to get the values, could you show me how you do it?Thanks in advance! and sorry if my english is not good... I´m from Argentina.I would really apreciate your answer because i´m really stuck in here.Rosy,
Andrea Vigato said:
infact as i said i managed to get the extra_fields column of a certain item ID and save the result in a var, the result is something like:
[{"id":"a","value":"b"},{"id":"c","value":"d"},{"id":"e","value":"f"}] etc etc
After that i exploded, trimmed and used a FOR to get the values.
If someone need help in all of this just contact me...so SOLVED.
Anyway thanks William for the replies :)
And in the default.php of the module i call the extrafields with this;<?php echo $item->prueba;?>The result is like yours:[{"id":"a","value":"b"},{"id":"c","value":"d"},{"id":"e","value":"f"}] etc etcBut now i don´t know how to get the values, could you show me how you do it?Thanks in advance! and sorry if my english is not good... I´m from Argentina.I would really apreciate your answer because i´m really stuck in here.Rosy,
Andrea Vigato said:
infact as i said i managed to get the extra_fields column of a certain item ID and save the result in a var, the result is something like:
[{"id":"a","value":"b"},{"id":"c","value":"d"},{"id":"e","value":"f"}] etc etc
After that i exploded, trimmed and used a FOR to get the values.
If someone need help in all of this just contact me...so SOLVED.
Anyway thanks William for the replies :)
Please Log in or Create an account to join the conversation.
- Andrea Vigato
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 50
13 years 10 months ago #97627
by Andrea Vigato
Replied by Andrea Vigato on topic Get Extrafields from external page
Hola soport :)
first of all it's a hell of a work, you will get all those values from the data and it's ok...now you have to use php string functions to cut first by the { } and then by the , and last by : .
As you can see the data is repeated the same....so i've made a function that separate id from data and get the value.
All i've used is explode PHP and some other php string functions.
I'm not at work now, maybe if you're still stuck i'll copy you some of my code ok?
first of all it's a hell of a work, you will get all those values from the data and it's ok...now you have to use php string functions to cut first by the { } and then by the , and last by : .
As you can see the data is repeated the same....so i've made a function that separate id from data and get the value.
All i've used is explode PHP and some other php string functions.
I'm not at work now, maybe if you're still stuck i'll copy you some of my code ok?
Please Log in or Create an account to join the conversation.
- soport
-
- Offline
- New Member
Less
More
- Posts: 2
13 years 10 months ago #97628
by soport
Replied by soport on topic Get Extrafields from external page
Hey, thanks for your quick reply :)
After a lot of searching and testing i finally made it work!! I´m really newbie in php so i don´t know if this is the best way to do it. Here it is:
In helper.php I added:$item->prueba = json_decode($item->extra_fields);
And In default.php:<?php echo $item->prueba[0]->value;?><br />
<?php echo $item->prueba[1]->value;?> [0] is for the first extra field, [1] por the second, etc.
This forum is really usefull, so i hope my answer could help someone else.Thanks again!
After a lot of searching and testing i finally made it work!! I´m really newbie in php so i don´t know if this is the best way to do it. Here it is:
In helper.php I added:$item->prueba = json_decode($item->extra_fields);
And In default.php:<?php echo $item->prueba[0]->value;?><br />
<?php echo $item->prueba[1]->value;?> [0] is for the first extra field, [1] por the second, etc.
This forum is really usefull, so i hope my answer could help someone else.Thanks again!
Please Log in or Create an account to join the conversation.
- Andrea Vigato
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 50
13 years 10 months ago #97629
by Andrea Vigato
Replied by Andrea Vigato on topic Get Extrafields from external page
works better than all my code :) thanks soport...never know about json_decode :)
Thanks to you..
Thanks to you..
Please Log in or Create an account to join the conversation.
- demonas
-
- Offline
- New Member
Less
More
- Posts: 16
13 years 10 months ago #97630
by demonas
Replied by demonas on topic Get Extrafields from external page
I want to do the same thing with mod_k2_content. Where do I put this line in the helper.php ?
Please Log in or Create an account to join the conversation.
- demonas
-
- Offline
- New Member
Less
More
- Posts: 16
13 years 10 months ago #97631
by demonas
Replied by demonas on topic Get Extrafields from external page
Never mind I solved. I had to check inside the module to show extra fields :-)
Please Log in or Create an account to join the conversation.