0

I always get this error if I try to load my site, even though the class does exist.

PHP Fatal error:  Uncaught Error: Class 'Company\\App\\Observer\\Frontend\\Controller\\ActionPredispatch'

app/code/Company/App/etc/frontend/events.xml:

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="controller_action_predispatch">
        <observer name="company_app_observer_frontend_controller_actionpredispatch_controller_action_predispatch"
                  instance="Company\App\Observer\Frontend\Controller\ActionPredispatch"/>
    </event>
</config>

app/code/Company/App/Observer/Frontend/Controller/ActionPredispatch.php:

<?php
declare(strict_types=1);

namespace Company\App\Observer\Frontend\Controller;
    
class ActionPredispatch implements \Magento\Framework\Event\ObserverInterface
{
    ...
}

I tried this:

rm -rf generated/*
php bin/magento setup:di:compile

But I still get the error.

The module is enabled of course.

2 Answers 2

0

I think it is a controller execute method related error.So please check your controller execute method like this or not.

public function execute(\Magento\Framework\Event\Observer $observer)
{
.....
}

3
0

Ok, this was a hard one!

The problem was caused by the file app/code/Company/App/Observer/Frontend/Controller/ActionPredispatch.php, because it had whitespace in the name ActionPredispatch.php.

After I removed the whitespace it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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