Class Application\Concrete\xxx not found

I took over from an old implementation some files with helper functions (where it worked). They were placed in Application\Concrete\MyHelpers\Base and some more files except Base. The new implementation can’t find it though and gives out the error: Class Application\Concrete\MyHelpers\Base not found.

In the Base.php file the namespace is set like this:
namespace Application\Concrete\MyHelpers;

In the controller files trying to use it it’s set like this:
use Application\Concrete\MyHelpers\Base;

And:
$bb = new Base();

I’m unsure if I need to register it somewhere or if something has changed in the last year and new version?

Alright, nothing I try works. And I find so many conflicting resources and information on the topic.

What is the most simple straight forward easy process if I want to include my own helper classes (currently sitting under /application/src/Concrete/MyHelpers) in blocks and single pages (including dashboard single pages + controllers).

Where to register, how to set up? As it’s not working in the new version I guess it might have gotten a complete new way to do it?

You can register custom classes from application/src directory in:
public/application/bootstrap/app.php

// Autoload custom classes from "public/application/src" directory
$strictLoader = new \Concrete\Core\Foundation\Psr4ClassLoader();
$strictLoader->addPrefix('Application', DIR_APPLICATION . '/' . DIRNAME_CLASSES);
$strictLoader->register();
2 Likes

Thank you Parasek.

I also found Creating Custom Code in the Application Directory :: Concrete CMS

and Autoloading

Both about that topic, yet it’s hard sometimes to see if it is still valid for current versions or not. Your data helped me too.

I did see however, that the culprit of my misery was a simple mistake. I’ve forgotten to put my data into a “Concrete” folder. That’s why it suddenly didn’t work anymore. Simple oversight. Took me way to long to realize it.

Now all works. Thank you again though, your data pointed me in the right direction.

1 Like