mega6382
mega6382

Reputation: 9396

Addind a class in zend framework 2 module

I have a Facebookbp.php in bleupage/module/Bleupage/src/Bleupage/facebook I want to include it in my controller.

the namespace is Bleupage\Facebookbp. Class name is Facebookbp

on top of my controller file I added:

use Bleupage\Facebookbp\Facebookbp;

I added this to my module.php

'Zend\Loader\StandardAutoloader' => array(
    'namespaces' => array(
       __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
       'Bleupage\Facebookbp' => __DIR__ . '/src/Bleupage/facebook',
    ),

It gives me

( ! ) Fatal error: Class 'Bleupage\Facebookbp\Facebookbp' not found in C:\xampp\htdocs\bleupage\module\Bleupage\src\Bleupage\Controller\BleupageController.php on line 19

I tried a lot of other methods none of them worked. How do I accomplish it.

Upvotes: 1

Views: 53

Answers (1)

Adam
Adam

Reputation: 873

You have src/Bleupage/facebook path but you are registering namespace for /src/facebook.

Also I have found that defining PSR-4 autoload config in composer and getting rid of Zend Autoloading entirely works better, you can then dump entire autoloading caches and gain performance. Thanks to that you also have entire configuration in one place.

EDIT:

I have created simple, skeleton project and added new namespace to the autoloader:

public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                    'Testing\Facebookbd' => __DIR__ . '/src/Test/facebook'
                ),
            ),
        );
    }

it works without any problems. I'm not sure what's the problem with your implementation. It looks ok for me. Can you show exact directory tree and content of the Facebookbp class?

Upvotes: 1

Related Questions