【发布时间】:2013-12-29 15:22:25
【问题描述】:
我想将我的自定义类“Authentication.php”添加到我的项目中,但我不明白该怎么做?
我已经阅读了很多关于外部库的操作指南,但没有任何作用。
ZendFramework/module/Firewall/Module.php
class Module
{
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
'MyNamespace' => __DIR__ . '/../../vendor/MyNamespace/lib/MyNamespace',
),
),
);
}
}
ZendFramework/vendor/MyNamespace/lib/MyNamespace /Authentication.php
<?php
class Authentication {
public function test()
{
die('Works fine');
}
}
?>
如何在我的控制器中调用我的外部库。
非常感谢!
【问题讨论】:
-
如果你把你的类放在module/ModuleName/src/ModuleName/中,你的类必须有'namespace ModuleName;'使用默认自动加载器的指令。它将可以调用 new \ModuleName\Authentication();
-
我想你忘了在
Authentication.php中添加命名空间部分 -
感谢 Mohamad,问题也出在命名空间上!再次感谢您!
标签: php zend-framework zend-framework2