How does zend customize automatic loading of classes like models? There is a models folder in the zend application that stores the Operation database class. it is very convenient to use it directly in the controller. Therefore, I have created a new teaa folder, but I don't know why, when I was new, I always reported a class error that could not be found. In addition, in bootst zend, how do I customize automatic loading of classes like models?
There is a models folder in the zend application that stores the Operation database class. it is very convenient to use it directly in the controller. Therefore, I have created a new teaa folder, but I don't know why, when I was new, I always reported a class error that could not be found. In addition, I have set the following automatic module loading in bootstrap, and the error message is that the class cannot be found.
Protected function _ initAutoloader ()
{
$ ModuleAutoloader = new Zend_Application_Module_Autoloader (array ('namespace '=> '', 'basepath' => APPLICATION_PATH ));
Return $ moduleAutoloader;
}
Finally, I thought the path was not imported. Add the path of the teaa folder to the set_include_path of the boot file index. php. The strange thing is that the class cannot be found due to an error.
------ Solution --------------------
The default namespace is
Application
Zend
If you want to customize. You can use the application. ini configuration file.
For example
bootstrap.class = "Bootstrap"
appnamespace = "Application"
autoloadernamespaces.test = "Test_"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
Autoloadernamespaces. test = "Test _" indicates the custom prefix.
For example, define a TestClass in the/library of the project.
The details are as follows:
/Library/Test/TestClass. php
File content:
class Test_TestClass {
public function show() {
echo "show";
}
}
In the action, you can use
public function indexAction()
{
$testObj = new Test_TestClass();
$testObj->show();
exit;
}
If you use the Module multi-Module mode, you need to use
Zend_Application_Module_Autoloader and
Use the Zend_Application_Module_Bootstrap class together.
Available in _ initAutoload
$ This-> getApplication ()
SetAutoloaderNamespaces
SetIncludePaths
To set the automatically loaded namespace and includepath.
Refer
Http://blog.csdn.net/mengxiangbaidu/article/details/7192855
Or official document