I need to use autoloading for my custom classes in Zend Framework 2.0. My custom library located in /vendor/Garvey/library/Garvey. I have a sim
Have a quick look at this post.
Now next step is add some code into our custom library.
First of all open a file ./vendor/Garvey/autoload_classmap.php
return array(
'Garvey\Module' => __DIR__ . '/Module.php',
'Garvey\Db\Table' => __DIR__ . '/library/Garvey/Db/Table/AbstractTable.php',
)
Next is ./vendor/Garvey/Module.php
namespace Garvey;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
class Module implements AutoloaderProviderInterface
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/library/' . __NAMESPACE__,
),
),
);
}
}
Now inside your library create a file inside a folder:
./vendor/Kdecom/library/Kdecom/Db/Table/AbstractTable.php
One final thing that we need to do which is add this library into your application.config.php file.
So your application.config.php file will looks something like this way...
return array(
'modules' => array(
'Application',
'Garvey'
),
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
'module_paths' => array(
'./module',
'./vendor',
),
),
);