How does zend customize automatic loading of classes like models?

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

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.