Getting text field value : what's the best way ?

More
10 years 2 months ago #49530 by Natwork
Hi everyone,
This morning, i got this message :

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 389121 bytes)

I got this on loading a category_items template with text only (no pics). On this page i get all items listed (something like 470 items, with 7 custom text field for each).
I was surprised to get this fatal error, so i would like to know how i can optimise the code.

Is one of these methods are better than the other one to get less memory used as possible :
Code:
$value = FlexicontentFields::getFieldDisplay($items[$i], 'field');
or
Code:
$value = $items[$i]->fieldvalues[29][0];

Regards

Please Log in or Create an account to join the conversation.

More
10 years 2 months ago #49531 by ggppdk
Hello

in early FLEXIcontent version it was very slow to list more than 50 items in same page

we have many optimization since but listing 470 items in same page will always be costly,

but you want to do 470 items ! in same page


ok you can in v2.2.0


Explanation
-- creation of every FLEXIcontent field HTML costs in call to its function

onDisplayFieldValue()
for CORE or CUSTOM

in v2.2.0 we changed this for CORE fields to make 1 call for all fields


in your case if you only want to get the text then do NOT call

$value = FlexicontentFields::getFieldDisplay($items[$i], 'fieldname');

because it does not just return value it RENDERS the PHP code for creating fields HTML according to parameters !!!


use:
$value = $items[$i]->fieldvalues[29][0];

which costs nothing in terms of extra memory and CPU


in case that you need HTML and not just values, then use:

// Render 'myfieldname' for ALL items at once, a little more efficient
FlexicontentFields::getFieldDisplay($items, 'myfieldname');

when you give items array it return nothing

to use the created HTML do:
echo $items[nnn]->fields->display;


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
10 years 2 months ago #49543 by Natwork
Thanks for your quick answer.

So i was using Flexicontent 2.1.3, i'll use 2.2 in few moments now ;)

As you suggested, I used
Code:
$value = $items[$i]->fieldvalues[29][0];
Where 29 is my custom field ID.

And yes, I didn't got PHP Fatal error anymore.
First, i have set php memory limit to 256mb, but now i can do the same with the original limit (128mb).

To optimize my template more, is there a way to get radio buttons value without rendering HTML?

Please Log in or Create an account to join the conversation.

More
10 years 2 months ago #49549 by micker
i think it will be a good article for FAQ !

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.350 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline