Invalid Controller Class (no Display)

96 views
Skip to first unread message

Sheldon Seale

unread,
Feb 4, 2025, 3:24:12 PMFeb 4
to Joomla! General Development
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

Steven Berkson

unread,
Feb 4, 2025, 5:33:54 PMFeb 4
to joomla-de...@googlegroups.com
Have you tried...

fetch('index.php?option=com_mtm&task=pricings.returnData') 

or using com_ajax since that is what you're doing and having an Ajax controller in your component. That is what I would recommend. 

Steven Berkson


From: joomla-de...@googlegroups.com <joomla-de...@googlegroups.com> on behalf of Sheldon Seale <srsea...@gmail.com>
Sent: Tuesday, February 4, 2025 10:52:20 AM
To: Joomla! General Development <joomla-de...@googlegroups.com>
Subject: [jgen] Invalid Controller Class (no Display)
 
--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/joomla-dev-general/55b0ca3c-67e0-4a41-adbe-8a1710b9fbe7n%40googlegroups.com.

Sheldon Seale

unread,
Feb 4, 2025, 7:13:51 PMFeb 4
to Joomla! General Development
Thank you, Steven. 

No, I haven't tried just pricings. I will do that, although I don't know how the environment will know it's a Controller... 
And the AJAX approach has occurred to me but I have no experience with it. I'll look into it.
I did try using Joomla\CMS\Router\Route to generate the URL but I'm still getting the same error.

Again, thank you for your suggestions. They are much appreciated.

Sheldon

Steven Berkson

unread,
Feb 4, 2025, 9:01:30 PMFeb 4
to joomla-de...@googlegroups.com

As I understand…

 

The controller is associated with the view and so any task is associated with the view’s controller unless you specifically specify a different one. Joomla! knows it is the controller for pricing because the controller is where it goes for directions.

I should have said, com_ajax is for modules and plugins. I have set a separate controller for ajax calls myself, but you should be able to do it with pricing.returnData. when you make the task pricing.returnData, pricing is the controller and returnData is the method.

 

See https://manual.joomla.org/docs/general-concepts/javascript/ajax/

Sheldon Seale

unread,
Feb 4, 2025, 11:05:38 PMFeb 4
to Joomla! General Development
Again, thanks to both of you for responding. As it turns out, Pricings.getData is the correct name and it does solve the Invalid Controller Class issue. There are other issues now but progress has been made.

If I figure out how to just retrieve the data string I want (and not an entire web page), I'll let you know.

This is my first time using this group and,I must say, I'm delighted at the response. Thank you all...

Sheldon

Steven Berkson

unread,
Feb 5, 2025, 12:04:24 AMFeb 5
to joomla-de...@googlegroups.com
Look at the Ajax link in the prior email. You should just get a json string back. It's gotta be in how you're calling it...

Steven Berkson


Sent: Tuesday, February 4, 2025 8:05:37 PM
Reply all
Reply to author
Forward
0 new messages