Reputation: 4546
How can I use the autoloader to find the class file 'templater' that lives in the same directory as the Zend directory?
|_ include
|_Zend
|_Templater.php
|_Smarty
|_root directory
I have stored the Zend folder and the smarty folder and other classes in de include folder outside the root directory.
I finally figured out how Zend could locate it's classes by adding it's location to the include_path.
Now I am stuck with the templaterclass that will be used by smarty.
How can I make the autoloader aware of the templaterclass and later on the smarty classes in the smartyfolder?
Upvotes: 0
Views: 290
Reputation: 18440
The Zend Framework autoloader is quite fussy about were classes are kept and how they are named.
In order to auto load, the templater class would need to be kept in include/Templater/Templater.php
and it would need to be named like this:-
class Templater_Templater
{
//Class stuff
}
You would call it in your model or controller like this:-
$templater = new Templater_Templater();
Before that would work however, you would need to add the following line to your application.ini file:-
autoloadernamespaces[] = "Templater_"
If templater is an external class you have downloaded that doesn't match the naming requirements and you can't change its name to suit the auto loader, then you will need to include the file where required, although it is still best to keep it in a subdirectory of includes. Or, as pointed out by David Weinraub, you can create a custom autoloader for this.
I am assuming that you are aware that 'includes' is not recommended directory structure for Zend Framework.
Upvotes: 1