adding JFactory::getSession(); results in white page

Home \ forums/topic \ adding JFactory::getSession(); results in white page

Support Home Page Forums Joomla Software Easy File Uploader Module adding JFactory::getSession(); results in white page

Tagged: 

This topic contains 9 replies, has 2 voices, and was last updated by  pablo222 2 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2998

    pablo222
    Participant

    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.

    #2999

    Michael Gilkes
    Keymaster

    @pablo222. Did you check your PHP error log to see what errors were logged?

    #3000

    pablo222
    Participant

    Sorry, 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

    #3001

    Michael Gilkes
    Keymaster

    @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.

    #3004

    pablo222
    Participant

    Thank 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.

    #3005

    Michael Gilkes
    Keymaster

    @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?

    #3006

    pablo222
    Participant

    I 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.

    #3007

    pablo222
    Participant

    Wait a minute, I think I missed something, let me check something out.

    • This reply was modified 2 months ago by  pablo222.
    #3009

    Michael Gilkes
    Keymaster

    @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.

    #3010

    pablo222
    Participant

    Yes, my last problem was a one character typo I missed. All good! Many thanks.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.