1

What is best possible approach to autoload classes from a PHP Project which is residing in

PHP Project

C:
|Projects
         |MyProject
                   |Classes
                           |CStudents.php
                                          |Student (ClassName)
                                                   |getStudentName() (Method)

All the classes have prefixes, such that, if the class is Students then it resides in CStudents.php

Right now I need to access these classes pull out some data and further with the Zend Framework 2 modules.

Zend Framework 2 Project:

C:
|Projects
         |Zend
              |module
                     |Application
                                 |Module.php

So what would be the simple and best possible approach for this. I need to autoload not more than 50 Classes.

EDIT: My question is almost similar to this one, but the only difference is that I have the requirement for Zend Framework 2.

As mentioned all Classes are residing in Classes folder, Class files have "C" [CStudent.php] as prefixes and the class names [Class Student]start without the prefixes, so lets say I want to access Student::getStudentName(); How can I accomplish that?

Thanks

4

1 回答 1

0

这是我如何使用自动加载器的示例。

模块.php

/**
 * Autoloader
 *
 * @return array
 */
public function getAutoloaderConfig()
{
    return array(
        'Zend\Loader\ClassMapAutoloader' => array(
            __DIR__ . '/autoload_classmap.php'
        )
    );
}

ZF2 附带了一个classmap_generator.php将构建模块中所有类所需的 PHP 数组。你可以运行classmap_generator -l modules/NameOfYourModule

这将输出一个名为的文件autoload_classmap.php并将其放置在您的 Module/NameOfYourModule 文件夹中。

您还可以在文档http://zf2.readthedocs.org/en/latest/modules/zend.loader.autoloader-factory.html中找到更多信息

于 2013-06-20T16:50:09.243 回答