My package’s name is “fhs”, the custom class is “Shortcuts”, stored in the file /packages/fhs/src/Shortcuts.php with namespace “Concrete\Package\Fhs”. I try to use it with “Concrete\Package\Fhs\Shortcuts”.
My first problem is, that I don’t understand the phrase
“Just add this boolean to your package’s controller.php:
$pkgAutoloaderMapCoreExtensions = true;”
in the documentation.
What does “add this boolean to your … controller.php” mean? As a property (public)? Or in the on_start()-function? Or elsewhere? I made it a public property and a variable in the on_start()-function but none of them worked.
I also tried to use my class with “Src” in the namespace, but no.
I also read this post:
and tried what was recommended there, but it didn’t work either.
There must be something I didn’t understand from the documentation. I remember sucessfully using my own classes in earlier versions of ConcreteCms (or rather Concrete5).
My code:
/packages/fhs/src/Shortcuts.php
<?php
namespace Concrete\Package\Fhs;
class Shortcuts {
public static function render($content) {
return $content;
}
}
/packages/fhs/controller.php
...
use Concrete\Package\Fhs\Shortcuts;
...
public function on_start() {
$this->pkg = $this;
$this->registerAssets();
echo Shortcuts::render('Hollebolle');
...
OUTPUT:
Error
Class “Concrete\Package\Fhs\Shortcuts” not found
$pkgAutoloaderMapCoreExtensions is only necessary when you want to avoid \Src as part of the automatically generated namespace and you are not otherwise mapping the namespace with $pkgAutoloaderRegistries.
If you use $pkgAutoloaderMapCoreExtensions, then the autoload mappings are going to be whatever is specified in that array.
Using $pkgAutoloaderMapCoreExtensions simply changes the automatic mapping from \Concrete\Package\Src\Fhs\Shortcuts to \Concrete\Package\Fhs\Shortcuts. But for this to work, you also have to move /packages/fhs/src/Shortcuts.php to /packages/fhs/src/Concrete/Shortcuts.php.
I’ve tried reworking that page to make this issue clearer. Let me know if I’ve missed anything or if there is still some confusion.