Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to add my custom class "Authentication.php" to my project but I don't understand how I have to do it ?

I have read many howto about the external libs but nothing work.

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(
            'ZendLoaderStandardAutoloader' => 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');
}


}

?>

How I can call my external lib in my controllers.

Thanks you very much !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
370 views
Welcome To Ask or Share your Answers For Others

1 Answer

I try like this:

1)

//module/Application/Module.php
public function getAutoloaderConfig()
{
    return array(
        'ZendLoaderStandardAutoloader' => array(
            'namespaces' => array(
                __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                'Mynamespace' => __DIR__ . '/../../vendor/Mynamespace',
            ),
        ),
    );
}

2)

//vendor/Mynamespace/MyClass.php
namespace Mynamespace;
class MyClass
{
    //...
}

3) I use it, for example in my controller:

use ZendMvcControllerAbstractActionController;
use MynamespaceMyClass;
class AdminController extends AbstractActionController
{
    public function indexAction()
    {
        $myclass = new MyClass();
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...