Zend Framework: Autoloading a Class Library

后端 未结 4 2068
说谎
说谎 2020-12-15 12:10

I\'ve got a class library in defined here .../projectname/library/Me/Myclass.php defined as follows:


I\'

相关标签:
4条回答
  • 2020-12-15 12:37

    You class needs to be name Me_Myclass:

    class Me_Myclass
    {
    }
    

    Move your library folder up a level so that you have the folder structure:

    /
        /application
        /library
        /public
    

    And then in your Bootstrap add the following to the _initAutoload():

        Zend_Loader_Autoloader::getInstance()->registerNamespace('Me_');
    
    0 讨论(0)
  • 2020-12-15 12:43

    I think @smack0007 means replace the contents of your _initAutoload method with Zend_Loader_Autoloader::getInstance()->registerNamespace('Me_'); so it looks like this:

    protected function _initAutoload()
    {
        Zend_Loader_Autoloader::getInstance()->registerNamespace('Me_');
    }
    
    0 讨论(0)
  • 2020-12-15 12:53

    you can define the autoload dir in the config.ini file like this:

    autoloaderNamespaces[] = "Me_"
    
    
    ;You could add as many as you want Classes dir:
    autoloaderNamespaces[] = "Another_"
    autoloaderNamespaces[] = "Third_"
    

    works 100%

    0 讨论(0)
  • 2020-12-15 12:55

    Not sure if this is your problem, but I just spent the last day and half trying to figure out my own similar problem (first time loading it up on Linux from Windows). Turns out I was blind to my library's folder name case.

    /library
        /Tlib
    

    is not the same as (on *nix)

    /library
        /tlib
    

    Class name is typically this

    class Tlib_FooMe {
     ...
    }
    

    Hope this helps someone who is similarly absentminded.

    0 讨论(0)
提交回复
热议问题