html - Return Different PHP Array Values Based on A User ID-Related Constant -
i working array of tokens html template. 2 of them ('{sys_menu}' , '{sub_menu}') used generate control buttons web application. right buttons show on login page before user's credential's validated, , need change code buttons hidden until after users login , reach main menu. when types http: address browser , arrives @ login page system starts session them in mysql sessions table user_id = 0. after login user_id changes whatever number assigned them @ initial registration (example: user_id = 54), , after logout @ end of session 0. tying constant buttons seems best solution , have found work in past under similar circumstances.
here original array:
$template_vars = array( '{lang_dir}' => $lang_text_dir, '{title}' => theme_page_title($section), '{charset}' => $charset, '{meta}' => $meta, '{gal_name}' => $config['gallery_name'], '{gal_description}' => $config['gallery_description'], '{sys_menu}' => theme_main_menu('sys_menu'), '{sub_menu}' => theme_main_menu('sub_menu'), '{admin_menu}' => theme_admin_mode_menu(), '{custom_header}' => $custom_header, '{javascript}' => theme_javascript_head(), '{message_block}' => theme_display_message_block(), );
the first thing did work references directly in html template. saw example on w3schools made type php script html , have resolve. didn't except echo bunch of text randomly page. found citation said had activate php .htaccess entry before work directly in html. didn't close deal either.
i know changing '{sys_menu}' , '{sub_menu}' values in array => "", produces results want (i.e. make menu buttons disappear). next thought i'll create if statement returns 2 versions of array based on circumstances, like:
if(user_id != 0) { return $template_vars = //first version of array full values// } else { return $template_vars = //second version of array => ""// }
but did cause application load terminate @ white screen no error feedback.
my recent attempt came read here on stack overflow. know cannot put if statements array. article @ link described workaround:
if statement within array declaration ...is possible?
so rewrote array follows:
template_vars = array( '{lang_dir}' => $lang_text_dir, '{title}' => theme_page_title($section), '{charset}' => $charset, '{meta}' => $meta, '{gal_name}' => $config['gallery_name'], '{gal_description}' => $config['gallery_description'], '{sys_menu}' => ('user_id != 0' ? theme_main_menu('sys_menu') : ""), '{sub_menu}' => ('user_id != 0' ? theme_main_menu('sub_menu') : ""), '{admin_menu}' => theme_admin_mode_menu(), '{custom_header}' => $custom_header, '{javascript}' => theme_javascript_head(), '{message_block}' => theme_display_message_block(), );
but seems have no effect @ all. application doesn't crash buttons static whether logged in or logged out.
my question is: missing? can see possible. i've been trying things day , half , seem dancing around solution. thoughts appreciated.
the problem here calling return. global include file there not context return application terminates. want assign variables.
if(user_id != 0) { $template_vars = //first version of array full values// } else { $template_vars = //second version of array => ""// }
Comments
Post a Comment