简体   繁体   中英

How to configure the Zend autoloader to load a custom path for resources before the default path

Separate but related to How to dynamically override forms and/or views using Zend? .

I want Zend to try to load custom forms/views before loading a set of default forms for a web application to let clients create custom forms for their application.

How do you configure the autoloader to load a different path before your default zend classes?

Like in the other question, you'll need to use a factory class. This class will check in a predefined directory the existence of the new form or otherwise the default form.

All you will need to do is something like:

// $formname is the parameter passed to the factory class
$defaultclassname = "Default_Form_{$formname}";
$classname = "New_Form_{$formname}";
if(file_exists("/path/to/directory/of/new/{$formname}.php"))
    return new $classname();
else
    return new $defaultclassname();

This will be done in your factory class, something like /MyLib/Form/Form_Factory.php

And then, in your controller:

$form = MyLib_Form_Factory::createForm('user');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM