问题描述
我需要在 Zend Framework 2.0 中为我的自定义类使用自动加载.我的自定义库位于 /vendor/Garvey/library/Garvey
.我在 /vendor/Garvey/library/Garvey/Db/Table/AbstractTable.php
中有一个简单的扩展 AbstractTable 类:
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 simple extended AbstractTable class in /vendor/Garvey/library/Garvey/Db/Table/AbstractTable.php
:
<?php
namespace GarveyDbTable;
use ZendDbTableAbstractTable;
abstract class AbstractTable extends AbstractTable
{
public function getItemById($id)
{
}
}
在 index.php 中,我有以下代码:
In the index.php I have the following code:
require_once 'vendor/ZendFramework/library/Zend/Loader/AutoloaderFactory.php';
ZendLoaderAutoloaderFactory::factory(array('ZendLoaderStandardAutoloader' => array(
'prefixes' => array(
'Garvey' => 'vendor/Garvey/library/Garvey',
)
)));
但是我有以下错误.我错过了什么?
But I have the following error. What I have missed?
Fatal error: Class 'GarveyDbTableAbstractTable' not found
提前致谢.
推荐答案
如果您将 'prefixes' 键更改为 'namespaces' 并指定如下路径,您原来的 index.php 也将起作用:
Your original index.php would also worked if you changed the 'prefixes' key to 'namespaces' and specify path like below:
ZendLoaderAutoloaderFactory::factory(array('ZendLoaderStandardAutoloader' => array(
'namespaces' => array(
'Garvey' => dirname(__DIR__) . '/vendor/Garvey',
)
)));
这篇关于Zend Framework 2.0 中的自动加载自定义库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!