This example describes resource autoloading usage in the Zend Framework. Share to everyone for your reference, as follows:
In general, in developing applications, it is possible that class filenames cannot be defined according to the recommendations of the standard Zend Framework, which means that your class files cannot be discovered by the autoloader. Zend_loader_autoloader_resource provides a solution.
A resource is simply a namespace (appended to the Autoloader's namespace) with a name corresponding to a component, and a path (relative to the base path of the autoloader), for example:
$loader = new Zend_application_module_autoloader (Array ( ' namespace ' = ' Blog ', ' basepath ' = Application_path. '/modules/blog ',));
The concrete examples are as follows:
path/to/some/resources/
|--forms/
| '--guestbook.php//Foo_form_guestbook
|--models/
| |--dbtable/
| | '--guestbook.php//Foo_model_dbtable_guestbook
| |--guestbook.php//Foo_model_guestbook
| '--guestbookmapper.php//Foo_model_guestbookmapper
To create a resource loader:
$loader = new Zend_loader_autoloader_resource (Array ( ' basepath ' = ' path/to/some/resources/', ' namespace ' = ' Foo ',));
Defining resource types
Zend_loader_autoloader_resourse::addresourcetype () has three parameters: the resource name, the relative resource path name of the specified resource path, and the resource type component prefix.
In the tree above, we have three types of resources: form (in subdirectory forms, the resource prefix is a form), model (in subdirectory models, the resource prefix is model), and dbtable (in subdirectory "Models/dbtable", the resource prefix is " Model_dbtable ").
It is defined as follows:
$loader->addresourcetype (' form ', ' Forms ', ' form ') ->addresourcetype (' model ', ' models ', ' model ') - >addresourcetype (' dbtable ', ' models/dbtable ', ' model_dbtable ');
You can also specify in the constructor
$resourceLoader = new Zend_loader_autoloader_resource (Array ( ' basepath ' = ' path/to/some/directory ', ' namespace ' = ' My ', ' resourcetypes ' = = Array ( ' acl ' = = Array ( ' path ' = = ' acls/ ', ' namespace ' = ' Acl ', ', ' form ' = = Array ( ' path ' = ' = ' forms/', ' namespace ' = > ' Form ', ), ' model ' = = Array ( ' path ' = ' models/', ' namespace ' = ' model ', ), ),));
Use to define Resources
$form = new Foo_form_guestbook (); $guestbook = new Foo_model_guestbook ();
Automatic loading of resources in modules
The Zend framework's MVC encourages the use of "modules", which, by default, typically has some resource types, and the Zend framework provides a standard catalog layout for a module. In this paradigm, the resource autoloader is very useful, and they are enabled by default.
Basic directory structure of the module:
configs/
Application.ini
controllers/
helpers/
forms/
layouts/
filters/
helpers/
scripts/
models/
services/
views/
filters/
helpers/
scripts/
bootstrap.php
You can extend Zend_application_module_bootstrap to create a module boot class bootstrap.php, specific resource loads and use similar to the default resource load.
More interested in Zend related content readers can view the topic: "Zend framework of the introductory tutorial", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Tutorial", "PHP object-oriented Programming introduction tutorial "," Introduction to Php+mysql Database Operation "and" PHP common database Operation Skills Summary "
I hope this article is helpful to you in PHP programming.