使用适当的命名约定访问Zend中的自定义库

问题描述:

Him Can anyone tell me how can I access the library in ZEND framework and what is the proper naming convention for libraries in ZEND. I have the following struture


--application
--docs
--library
    --myLibrary.php (class name is also same)
--public

How can I access this library in my model?

他 任何人都告诉我如何在ZEND框架中访问库以及库的正确命名约定是什么 在ZEND。 我有以下结构 p>


   -  application 
  -  docs 
  -  library 
 --myLibrary.php(类名是 同样)
  -  public 
  code>  pre> 
 
 

如何在模型中访问此库? p> div>

If your library is really a single class called myLibrary stored in library/myLibrary.php, then you should be able to add the following to your application/configs/applicatiom.ini file:

autoloadernamespaces[] = "myLibrary"

Then you should be able to instantiate a myLibrary object using:

$lib = new myLibrary();

Well if your library folder is on the include path then you can use myLibrary directly.

The best way is to create your own library directory:

library
    My
        Library.php
    Zend

Add this to ypur index.php:

Zend_Loader_Autoloader::getInstance()->registerNamespace('My_');

And use this class:

$obj = new My_Library();