How to indicate zend framework where my custom classes are

前端 未结 4 834
不知归路
不知归路 2020-12-16 05:38

I have a folder with custom classes in a ZF 1.10 application. The folder is located in /library. How can I tell ZF where they are? Both application.ini and index.php set the

4条回答
  •  攒了一身酷
    2020-12-16 06:20

    There are many possible solutions. The most common, when using Zend Application, is to register the namespace in application.ini by adding:

    autoloaderNamespaces[] = "Example_"
    

    Other solutions:

    • Add your dir to include_path using set_include_path() (ad hoc solution)
    • Follow PEAR naming conventions (so the path resolving was possible)

    Set up autoloader in Bootstrap.php:

    protected function _initAutoloader()
    {
        $autoloader = Zend_Loader_Autoloader::getInstance();
        $autoloader->registerNamespace("Example"); // or Example_
    }
    

    Eventually, set up module or resource autoloader, eg.

    $resourceLoader->addResourceTypes(array(
         'acl' => array(
            'path'      => 'acls/',
            'namespace' => 'Acl',
        ),
        'example' => array(
            'path'      => 'examples/',
            'namespace' => 'Example',
        ),        
    ));
    

提交回复
热议问题