Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 2224

Joomla! 5.x Coding • Problem Accessing Joomla Module Data via Custom API (Resource Not Registered)

$
0
0
Hi Joomla Devs,

I’m developing a custom API to access data from my Joomla module (mod_bahamasgastracker). The goal is to pull gas prices from the module so I can use it in a Progressive Web App (PWA).

However, I keep encountering this error:
"Resource 'Joomla\Session\SessionInterface' has not been registered with the container."

What I’ve Tried So Far
Here’s what I’ve done to connect to the Joomla environment:
  • Set JPATH_BASE to: /home/www/eagleproweb.com
  • Included core Joomla files: defines.php and framework.php
  • Used Factory::getApplication('site') and initialized it with $app->initialise();
  • I’m using Joomla 5.x and PHP 8.2.
Despite this, I keep getting the error:
"Resource 'Joomla\Session\SessionInterface' has not been registered with the container."

Current Code

Code:

define('_JEXEC', 1);define('JPATH_BASE', '/home/www/eagleproweb.com');require_once JPATH_BASE . '/includes/defines.php';require_once JPATH_BASE . '/includes/framework.php';use Joomla\CMS\Factory;try {    $app = Factory::getApplication('site');    $app->initialise();} catch (Exception $e) {    echo json_encode([        'error' => 'Failed to initialize Joomla',        'message' => $e->getMessage()    ]);    exit();}
What I Expect to Happen
I’m trying to pull module parameters for mod_bahamasgastracker (gas prices) to use in a PWA.
I expect the API to return JSON-formatted data, similar to this:

Code:

[  { "gas_station": "Shell", "gas_price": "5.38", "diesel_price": "4.84" },  { "gas_station": "Esso", "gas_price": "5.45", "diesel_price": "4.77" }]

I’m looking for guidance on how to correctly register or access Joomla's container resources.

Should I be using a different method to access ModuleHelper or Factory::getApplication('site')?
Do I need to explicitly register Joomla\Session\SessionInterface somehow?

Any help or pointers would be greatly appreciated.

Thanks in advance!

ZeM

Statistics: Posted by zema2023 — Sun Dec 15, 2024 10:12 pm



Viewing all articles
Browse latest Browse all 2224

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>