Zend How to customize automatic loading of classes like models

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.