Zend How to customize automatic loading of classes like models?
Zend Application There is a models folder is to store the operation of the database class, in the controller directly new can be used, very convenient, so I also created a TEAA folder, but do not know why, in new when always reported to find the wrong class. And I have set the following automatic module loading in the bootstrap or the error cannot find the class.
protected function _initautoloader ()
{
$moduleAutoloader = new Zend_application_module_autoloader (Array (' namespace ' = ', ' basepath ' = = Application_ PATH));
return $moduleAutoloader;
}
Finally, I thought the path was not imported. In the boot file index.php Set_include_path also add Teaa folder path, strange is still error said to find the class, please expert pointing ah.
------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_" represents a custom prefix.
For example, in the/library of a project, define a TestClass
Specific as follows:
/library/test/testclass.php
File contents:
Class Test_testclass {
Public function Show () {
echo "Show";
}
}
In action, you can use the
Public Function indexaction ()
{
$TESTOBJ = new Test_testclass ();
$TESTOBJ->show ();
Exit
}
If you are using module multi-mode, you need to use the
Zend_application_module_autoloader and
The Zend_application_module_bootstrap class is used together.
Can be used in _initautoload
$this->getapplication ()
Setautoloadernamespaces
Setincludepaths
To set the automatically loaded namespaces and Includepath
can refer to
http://blog.csdn.net/mengxiangbaidu/article/details/7192855
or official documents