C5-8.3: How to add my own class to a package?

Permalink
I have a package with a block. I want to add my own class to the package which I will use from the block. I've created, say, a MyClass.php in the package folder 'src'.

MyClass.php has the following:
namespace Concrete\Package\MyPackage\Src
class MyClass extends Controller
{
    public function show($string str = '')
    {
    }

My block's controller has this:
use Concrete\Package\MyPackage\Src\MyClass as ClassInst;
class Controller extends BlockController
{
    public function view() 
    {
        $img = ClassInst::show('');
    }

I tells me "Class 'Concrete\Package\MyPackage\Src\MyClass' not found"

I tried to put this into the package controller:
protected $pkgAutoloaderRegistries = array(
    'src/MyClass' => '\MyClass'
    );

Still tells me my class not found.

What am I doing wrong or missing?

Thank you.

linuxoid
View Replies:
hutman replied on at Permalink Reply
hutman
Change

protected $pkgAutoloaderRegistries = array(
    'src/MyClass' => '\MyClass'
);

to
protected $pkgAutoloaderRegistries = array(
    'src' => '\Concrete\Package\MyPackage\Src'
);
pvernaglia replied on at Permalink Reply
pvernaglia
I'm having trouble wit this too, did you get it to work?
linuxoid replied on at Permalink Reply
linuxoid
Yes, I did. I have the following:

1. Create a file with a name in the form MyClassName.php in my_package_name/src/MyBlockName/
2. MyClassName.php:
<?php
namespace MyBlockName;
class MyClassName
{
...

3. Package controller.php:
protected $pkgAutoloaderRegistries = array(
        'src/MyBlockName' => '\MyBlockName'
    );

4. Block name in the form my_block_name
5. Block controller.php:
use MyBlockName\MyClassName;
...
    public function view() 
    {
        $my_class = new MyClassName();
    }