1

To create thumbnails & cache files, I have to access my already created Ajax Functions inside my helper.php file.

I'm already able to call the functions within the frontend (button that is visible when debug is active calls the js functions) -- all fine from frontend -- but if I add the same js into the backend I get the error:

The file at mod_modname/helper.php does not exist.

My request looks like this:

let data = {
        'moduleId': '{$moduleId}'
    };
let request = {
        'url' : '{$url}', // is JURI::current() //--> already tried without
        'option': 'com_ajax',
        'module': 'modname',
        'method': 'getImages',
        'data': str_data,
        'format': 'json'
    };

so JURI::current here is: mydomain.tld/administrator/index.php

The initial call that did not work is located in 'mod_mymodname/models/fields/myCustomfield.php' as follows:

protected function getInput()
    {
        $formData = json_decode($this->form->getData('jform'),'true');

        if(isset($formData['id'])) {
            $moduleId = $formData['id'];

            include JPATH_ROOT.'/modules/mod_modname/helper/buildCache.js.php';

            $doc = JFactory::getDocument();
            $doc->addScriptDeclaration($buildCacheActivation);
...

Keep in mind - all works from frontend, just from module backend (where I also want to be able to "create" the cache, I receive that error).

I think it could be something with the path / the different locations from where the script will be called?

Unfortunately, I did not find any solution for this issue in the guides.

Edit: Added Ajax Call URL Frontend:

url=http%3A%2F%2Flocalhost%2Fjoomla1%2Findex.php&option=com_ajax&module=modulename&method=getGalleries&data=%7B%22moduleId%22%3A%22110%22%7D&format=json

Backend:

url=http%3A%2F%2Flocalhost%2Fjoomla1%2Findex.php&option=com_ajax&module=modulename&method=getGalleries&data=%7B%22moduleId%22%3A%22110%22%7D&format=json

So its the same....

different are the "Request URL" which is as follows from backend: http://localhost/joomla1/administrator/index.php?option=com_modules&view=module&layout=edit&id=110

1

If you still want to use the frontend urls from backend, make sure to call the frontend site appropriately.

Your should use Juri::root() to get site url from administrator instead of Juri::base() or Juri::current().

Juri::root() --> http://mysite.local

Juri::base() --> http://mysite.local/administrator

Juri::current() --> http://mysite.local/administrator/index.php?option=some_component&view=some_view

  • I can try that but if i understand the guides correct - the module has to be published „on all pages“ that this could work, right? – Proximate Jul 20 at 14:56
  • nah sorry - its the same behaviour / reponse when i am try to call the ajax request from backend with JURI::root(): {success: false, message: "The file at mod_modname/helper.php does not exist.", messages: null, data: null} – Proximate Jul 20 at 15:04
  • what does the complete ajax url look like? you can examine this in your browsers dev tools -> network -> under the XHR tab. – Somy Ericsson Jul 20 at 17:24
  • added those AJAX URL's into my question for better readability – Proximate Jul 20 at 18:02
  • 1
    I think I can figure out what could be the issue, com_ajax is attempting to look for the helper file in the backend because, the JPATH_BASE constant is populated with an administrator path... Do this as an experiment, go to components/com_ajax/ajax.php and change this line 58 from: ``` $helperFile = JPATH_BASE . '/modules/mod_' . $module . '/helper.php';``` to ``` $helperFile = JPATH_SITE . '/modules/mod_' . $module . '/helper.php';``` and see if my theory is proven. You can revert back to the original code soon after. – Somy Ericsson Jul 20 at 19:06
0

I'm leaving this here for future readers:

The End-Solution after the analysis with Somy Ericsson was to create a second module. For the AJAX-Backend tasks i've packed my existing frontend module and this second one into a Package. The administrator module contains a helper file that response to the AJAX calls made from my frontend module's backend.

That was necessary because of the fact that the com_ajax is searching for the helper file via the JPATH_BASE constant.

in fact if called from frontend the path is: modules/mod_modname/helper.php

and from backend via customfield: administrator/modules/mod_modname/helper.php

because we cannot change where com_ajax searches for the helper-file the workaround with a second module was necessary.

thanks to Somy for pointing me into the right direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.