Template Caching?

Renari

Member
I have a while loop generating a list of users like so.
PHP:
while ($user = $query->fetch()) {
    $params = $template->getParams();
    $hookParams += $user;
    $params += $hookParams;
    $content .= $template->create('template', $params);
}

However when this is being output whoever the first user in the query is, it will output that template for the first user the amount of times the while loop would have run. Is this problem related to template caching?
 
I believe this is due to the shorthand += operator taking the original in case of conflicts when merging arrays, try $hookParams = $user + $hookParams and $params = $hookParams + $params



Also a side note, I recommend having a PHP opcode cache and enabling the 'templates as files' option when using a lot of $template->create's like that, otherwise it queries the database and parses the template over and over again each time
 
Thanks, you were right also thanks for the suggestion on improving the code I've never used an opcode cache before and I'll read up on it. I wasn't aware that += prioritized the original array, rather I believed it to function the opposite.
 
Thanks, you were right also thanks for the suggestion on improving the code I've never used an opcode cache before and I'll read up on it. I wasn't aware that += prioritized the original array, rather I believed it to function the opposite.

Yeah it's very unintuitive for the array before the + to take priority, typical PHP :P
 
Back
Top Bottom