Customizing SMF > SMF Coding Discussion
how is $context initialized?
(1/1)
poda19:
hi
i'm new to SMF
can anyone explain how i can know where global variables like $context are initialized?
for example:
--- Code: ---// Get all the messages...
while ($message = $context['get_message']())...
--- End code ---
how should i know what is the contents of 'get_message' and what $message variable contains after this line?
(i know i can print the contents of variables but i wanted to know if there is a better way)
thanks
i love your forums :-*
Arantor:
$context['get_message'] is declared in Display.php and is the name of a function to run to retrieve the next row of a query that fetches messages.
Look at prepareDisplayContext() in Display.php, the return of that function is what $message is declared as.
Suki:
Hi, welcome to SMF.
context vars are generated on the Source files, for example, $context['get_message'] is generated on Sources/Display.php
$context['get_message'] isn't the simplest example as it is a little bit complicated.
$context vars are usually used to past values to the "view", aka, the template and their scope is local in most cases, that is, $context['get_message'] will not be available on the profile page for example.
To generate a new context var is as simple as declaring it: $context['my_awesome_value'] = 1; on the source file, then on the template you globalize $context and you cna use it:
global $context;
echo $context['my_awesome_value'];
The easiest way to find out about context and its content is doing a print_r on it.
poda19:
thanks a lot
got all my answers
again, i love your forums :-*
Navigation
[0] Message Index
Go to full version