? No Code Attached Yet
avatar fvlasenko
fvlasenko
28 Jul 2020

What needs to be fixed

com_ajax

Why this should be fixed

Add functional ajax in admin module

How would you fix it

replace
$helperFile = JPATH_BASE . '/modules/mod_' . $module . '/helper.php';
to
$basePath = ($table->client_id) ? JPATH_ADMINISTRATOR : JPATH_SITE; $helperFile = $basePath . '/modules/mod_' . $module . '/helper.php';
remove
// Load language file for module $basePath = JPATH_BASE;

Side Effects expected

No

avatar fvlasenko fvlasenko - open - 28 Jul 2020
avatar joomla-cms-bot joomla-cms-bot - change - 28 Jul 2020
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 28 Jul 2020
avatar fvlasenko fvlasenko - change - 28 Jul 2020
The description was changed
avatar fvlasenko fvlasenko - edited - 28 Jul 2020
avatar fvlasenko fvlasenko - change - 28 Jul 2020
The description was changed
avatar fvlasenko fvlasenko - edited - 28 Jul 2020
avatar Fedik
Fedik - comment - 28 Jul 2020

JPATH_BASE already holds a correct path, for an administrator and for a site.
If you need access to administrator module then do request to /administrator.

avatar SharkyKZ
SharkyKZ - comment - 28 Jul 2020

Duplicate #25684.

Using client ID would be fine except that we can't determine it based on module name. Modules with the same name can be installed to both backend and frontend, e.g. like core mod_feed or mod_custom modules.

avatar Fedik
Fedik - comment - 28 Jul 2020

I do not think it is an issue, you just have to do a correct request:

for site modules: /index.php?option=com_ajax&module=foobar&format=json
for admin modules: /administrator/index.php?option=com_ajax&module=foobar&format=json

Same as with any component.

avatar SharkyKZ
SharkyKZ - comment - 29 Jul 2020

This is no good if you want to use Ajax in module form.

avatar Fedik
Fedik - comment - 29 Jul 2020

why you ever need that? :)

It the same as for components, you cannot execute Site component by doing request to Backend, and vice versa. The same applies to the modules.

avatar SharkyKZ
SharkyKZ - comment - 29 Jul 2020

To update form fields using AJAX. It's a reasonable use case.

avatar Fedik
Fedik - comment - 30 Jul 2020

Ah okay, I finally get it, it for a module configuration form, not for a module itself ?

Well, then, just add &client=0 to query, and update com_ajax to use it.
So you can call site module from backend. Eg:
/administrator/index.php?option=com_ajax&module=foobar&format=json&client=0

But, it should be forbidden to call administrator module from the site. So if someone call &client=1 from the site then com_ajax should throw an error.

avatar fvlasenko
fvlasenko - comment - 31 Jul 2020

@Fedik i use this in admin panel modules
client="administrator"

avatar Hackwar Hackwar - change - 20 Feb 2023
Labels Added: ? No Code Attached Yet
Removed: ?
avatar Hackwar Hackwar - labeled - 20 Feb 2023

Add a Comment

Login with GitHub to post a comment