How to tell zend framework where my custom classes are

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 library path, but then ZF cannot find the files.

thanks

+6
zend-framework bootstrapping
source share
4 answers

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

 autoloaderNamespaces[] = "Example_" 

Other solutions:

  • Add your include_path directory with set_include_path() (ad hoc)
  • Follow the PEAR naming conventions (to allow the path was possible)

Install the autoloader in Bootstrap.php :

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

Finally, configure a module or autoloader resource , for example.

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

We often encounter the problem of writing our own custom functions or classes and their placement.

So, to add a custom class (or custom library), you can use the zend framework autoload namespaces.

Add the following line to the application.ini file

 autoloaderNamespaces.custom = "Custom_" 

OR

 autoloaderNamespaces[] = "Custom_" 

All user classes will be stored in the library directory. Create the name of the "Custom" folder in the library folder (which is defined in application.ini).

Classes will have the prefix "Custom_" when declared in a file (for example, Custom_Test)

Now we can use this class as $test = new Custom_Test() in our application.

+24
source share

Give up this senior Zend Framework tutorial from Rob Allen , specifically on page 4, where he talks about the bootloader. His new tutorials, as well as excellent ones, seem to rely on the Zend Tool to make the application creation and mask it.

One thing that bothered me, however, was that you mentioned that the folder you want to include is the public / library. If you do not intend to share your code with the world, I strongly recommend that you place it in another place ... if you do not have another β€œpublic” folder that is not accessible to the public (in this case, you may want to rename it to avoid confusion in the future) .

+1
source share

Add your own library to composer.json:

 "autoload": { "psr-0": {"Your": "vendor/My/library"} }, 

and run composer update

0
source share

All Articles