Hello all,
When I try to invoke a method in a custom Controller, I keep getting the "Invalid Controller Class" error (from line 174 of the Component Controller.php script). The error includes the name of the invalid controller, in my case PricingsController, hence the full error is "Invalid Controller Class: PricingsController". That controller is in the same folder as the DisplayController and I invoke it from a tmpl/pricings/default.php script with a Javascript "fetch"command.
The code is very straightforward, the default script has a button that, when clicked, issues a fetch to a URL ("index.php?option=com_mtm&task=PricingsController.getData"). The controller simply returns a text string (baby steps...).
default.php
<?php
defined('_JEXEC') or die('Pricings View Died');
use Joomla\CMS\Factory;
$user = Factory::getApplication()->getIdentity();
if($user)
{
// print_r($user);
};
echo 'Made-To-Measure Pricings';
?>
<html>
<body>
<h2>Pricing</h2>
<button type='button' class='btn btn-success' onclick='getData()'>Get Data</button>
<!-- Call a script using Fetch -->
<script>
function getData()
{
fetch('index.php?option=com_mtm&task=PricingsController.returnData')
.then(response => response.text())
.then(data => alert(data));
};
</script>
</body>
</html>
PricingsController.php
<?php
namespace Demerci\Component\Mtm\Site\Controller;
defined('_JEXEC') or die('Pricings Controller Died');
use Joomla\CMS\MVC\Controller\BaseController;
class PricingsController extends BaseController
{
public function returnData()
{
$datais = 'Back at ya!';
return $datais;
}
}
My environment is:
Joomla 5.2.3
PHP 8.3
MySQL 8.0.4
WAMPserver64 3.3.6
Backward Compatibility Plugin is disabled
I feel I'm overlooking something. I've been staring at this so long, I'm not sure I'm seeing straight. Maybe some fresh eyes and someone with more experience than I can help out.
Any and all suggestions, assistance, encouragement greatly appreciated.
Thank you,
Sheldon