2

Here is the simplified error:

InvalidArgumentException: Class "\Drupal\prepcart\Controller\PrepCartController" does not exist. in Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition() (line 24 of core/lib/Drupal/Core/DependencyInjection/ClassResolver.php).

Full Stack Trace:

The website encountered an unexpected error. Please try again later. InvalidArgumentException: Class "\Drupal\prepcart\Controller\PrepCartController" does not exist. in Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition() (line 24 of core/lib/Drupal/Core/DependencyInjection/ClassResolver.php). Drupal\Core\Controller\ControllerResolver->createController('\Drupal\prepcart\Controller\PrepCartController::content') (Line: 74) Drupal\Core\Controller\ControllerResolver->getControllerFromDefinition('\Drupal\prepcart\Controller\PrepCartController::content', '/cart') (Line: 91) Drupal\Core\Controller\ControllerResolver->getController(Object) (Line: 132) Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64) Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57) Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47) Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 98) Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 77) Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23) Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 628) Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Relevant information: Drupal Core 8.1.8 (I know 8.2 is out but this shouldn't matter I believe - we are pinned to this version due to Lightning)

And here is the relevant files involved:

PrepCartController.php

<?php
/**
 * @file
 * Contains \Drupal\prepcart\Controller\PrepCartController.
 */
namespace Drupal\prepcart\Controller;
use Drupal\Core\Controller\ControllerBase;
class PrepCartController extends ControllerBase {
  public function content() {
    return array(
      '#type' => 'markup',
      '#markup' => $this->t('Hello, IHM!'),
    );
  }
};

To make life easier this is the directory structure:

drwxr-xr-x   170B Oct 18 07:05 ./
-rw-r--r--   222B Oct 18 06:36 ./prepcart.info.yml
-rw-r--r--   195B Oct 18 07:05 ./prepcart.routing.yml
drwxr-xr-x   102B Oct 18 06:53 ./src/
drwxr-xr-x   102B Oct 18 06:54 ./src/Controller/
-rw-r--r--   349B Oct 18 06:54 ./src/Controller/PrepCartController.php

For some reason the module won't show on the modules page but I can interact with it fine on the CLI using drush?

Trust me when I say I have been ALL over Google and Stack for this. Major love to whomever can help me here.

2
  • 1
    can you add the content of the routing file as well?
    – Berdir
    Commented Oct 23, 2016 at 12:14
  • or even share it on github or so, might be easier to reproduce.
    – Berdir
    Commented Oct 23, 2016 at 12:14

2 Answers 2

4

I had the same problem once, clearing caches from drush was not sufficient. I cleared them from the drupal interface and the error message was gone...

3
  • 1
    also for me, but why ?????
    – john Smith
    Commented Mar 17, 2023 at 8:32
  • Worked for me also, Thanks, dont know why
    – Zuhair
    Commented Nov 16, 2023 at 11:09
  • Worked for me too.
    – Rifas Ali
    Commented Mar 16 at 9:36
0

I am facing Similar Kind of Issue once at drupal 10

My code:

Routing File:

learning.learningpage:
  path: "myworld"
  defaults:
    _controller: 'Drupal\learning\Controller\MyLearningWorldController::showData'
    _title: "This is my learning World"
  requirements:
    _permission: "content access"

Controller:

<?php
namespace Drupal\learning\Controller;
use Drupal\Core\Controller\ControllerBase;

class MyLearningWorldController extends ControllerBase{

    public function showData(){
        return [
            '#markup' => 'Enter My learning World'
        ];
    }
}

I got error :

InvalidArgumentException: Class "Drupal\learning\Controller\MyLearningWorldController" does not exist. in Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition() (line 24 of C:\xampp\htdocs\d10\web\core\lib\Drupal\Core\DependencyInjection\ClassResolver.php).

I have clear cache using Drush , but error still not solved.

After that I have clear cache from admin panel (admin/config/development/performance). Then issue solved for me.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Jun 19, 2023 at 12:21

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.