The following warnings occurred: | ||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Generating navigation markup within function fails - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23) +--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26) +--- Thread: Generating navigation markup within function fails (/showthread.php?tid=1211) |
Generating navigation markup within function fails - mlam19 - 11-14-2018 Greetings, I would like to write a class that contains function that serves as a sort of wrapper around some UserSpice 4 features. I'm mostly concerned with controlling when and where in my own program the UserSpice HTML markup is generated and used. Unfortunately, I've run into some problems using UserSpice code from within functions. To start, first I modified step 5 from the Getting Started instructions. I skipped the generation of the header, and saved the output of the navigation markup to a variable. The following script works when no user is logged in, and when a user is logged in (script #1): PHP Code: <!DOCTYPE html> Next, I moved the code into a function as follows (script #2): PHP Code: <!DOCTYPE html> Script #2 works when nobody is logged in, but after logging in an error occurs when processing navigation.php. The following appears in the Apache error log (I have replace the paths with --- but the remainder should be sufficient): Code: [client 127.0.0.1:52386] PHP Fatal error: Uncaught Error: Call to a member function data() on null in ---/users/helpers/us_helpers.php:1010 The data() function is apparently a member of the global $user variable. $user seems to exists before processing navigation.php, and I am uncertain when and why it becomes null. Is there some other way to massage things to get the function working? RE: Generating navigation markup within function fails - mudmin - 11-14-2018 What happens if you put global $user; on the line right after function initialize() { RE: Generating navigation markup within function fails - mlam19 - 11-15-2018 (11-14-2018, 03:33 PM)mudmin Wrote: What happens if you put That makes it work. Thanks! |