Support Home Page › Forums › Joomla Software › Easy File Uploader Module › adding JFactory::getSession(); results in white page
Tagged: getSession
This topic contains 9 replies, has 2 voices, and was last updated by pablo222 2 years ago.
-
AuthorPosts
-
March 31, 2019 at 12:13 am #2998
In a previous version of Easy File Uploader, I modified the code in /home/khqxebud/public_html/modules/mod_easyfileuploader/helper.php slightly by adding a mysql update whenever a new file was uploaded, and set a session variable to communicate back to the Joomla article that I am running the module from.
In the new version, the code has been moved to /home/khqxebud/public_html/modules/mod_easyfileuploader/Helper/EasyFileUploaderHelper.php. As soon as I add
$session = JFactory::getSession();
to public static function getFileToUpload, the upload button results in a white page and no upload. I am quite baffled by this and can’t explain it.March 31, 2019 at 6:10 pm #2999@pablo222. Did you check your PHP error log to see what errors were logged?
April 10, 2019 at 1:54 pm #3000Sorry, thought I posted this answer previously but it’s not showing up. Set Joomla error reporting to maximum. The page shows:
Error: 0 – Class ‘ValorApps\Module\EasyFileUploader\Site\Helper\JFactory’ not found
April 12, 2019 at 11:39 am #3001@pablo222. Thanks for posting the error. This happens as a result of namespacing in PHP. To fix this, instead of typing:
$session = JFactory::getSession();You can do one of the following:
1. $session = \JFactory::getSession();
2. use Joomla\CMS\Factory; /* < -- place this use statement the top of the file*/ $session = Factory::getSession();
3. $session = \Joomla\CMS\Factory::getSession();Hope this helps.
-
This reply was modified 2 years ago by
Michael Gilkes.
-
This reply was modified 2 years ago by
Michael Gilkes.
April 13, 2019 at 12:30 pm #3004Thank you Michael – that did the trick on finding JFactory library. However, now it seems the session variables in my Joomla article are not making it to EasyFileUploaderHelper.php. Most likely the namespace issue – I am a long time developer but new to Joomla, done some php but new to namespace issue – what would I do with the Joomla article php code so they are using the same session variables?
Thanks again.
April 13, 2019 at 2:36 pm #3005@pablo222. I am glad it fixed your namespacing issue. I am not too sure what you are trying to do with Factory::getSession(). Session information is available as long as you are calling PHP scripts in the same session. There is no code in EasyFileUploaderHelper.php preventing this, as you can tell from examining the code. The question is: what are you doing with the session variable once you get it?
April 13, 2019 at 2:52 pm #3006I did add the same line “namespace ValorApps\Module\EasyFileUploader\Site\Helper;” to the php code section in my joomla article, and now I get
Error: 0 – syntax error, unexpected ‘ValorApps’ (T_STRING), expecting \\ (T_NS_SEPARATOR)Thanks again.
April 13, 2019 at 5:28 pm #3007Wait a minute, I think I missed something, let me check something out.
-
This reply was modified 2 years ago by
pablo222.
April 13, 2019 at 5:49 pm #3009@pablo222. You are not supposed to add any namespace code to the article. I don’t know what changes you are making. So, I can’t really advise you properly, but it seems you are getting confused with regard to using namespaces, but you don’t need to do that.
April 13, 2019 at 8:04 pm #3010Yes, my last problem was a one character typo I missed. All good! Many thanks.
-
This reply was modified 2 years ago by
-
AuthorPosts
You must be logged in to reply to this topic.