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 path to the library but then ZF can't find the files.
Thank you
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 path to the library but then ZF can't find the files.
Thank you
There are many possible solutions. The most common, when using Zend Application, is to register the namespace in
application.ini
by adding:Other solutions:
include_path
usingset_include_path()
(ad hoc solution)Set up autoloader in
Bootstrap.php
:Eventually, set up module or resource autoloader, eg.
We often come across a problem of writing our own custom functions or classes and where to place them.
So to add custom class (or custom library) one can use zend framework's autoloader namespaces.
Add the below line in application.ini file
OR
All the custom classes will be kept under library directory. Create a folder name 'Custom' (which is defined in application.ini) in the library directory.
Classes will be prefixed with 'Custom_' at declaration in the file (e.g. Custom_Test)
Now we can use this class as
$test = new Custom_Test()
, in our application.Add your custom library to composer.json:
and run composer update
Check out this older Zend Framework tutorial from Rob Allen, specifically on page 4, where he talks about the bootstrapper. His newer tutorials, as excellent as they are, appear to rely on Zend Tool to do the application creation and gloss over this.
One thing that alarmed me, however, was that you mentioned that the folder you're trying to include is public/library. Unless you intentionally want to share your code with the world, I would strongly suggest you place it elsewhere...unless you've got a different "public" folder not shared with the public (in which case you may want to consider renaming it to avoid future confusion).