0

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?

Community
  • 1
  • 1
pfyon
  • 332
  • 1
  • 6
  • 10
  • While it doesn't solve this problem, my solution was to create a second set of views and forms that extended our default views and forms, then load them all the time. Not as nice as I'd like, but it has its advantages. – pfyon Sep 23 '10 at 14:46

1 Answers1

0

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');
Keyne Viana
  • 6,194
  • 2
  • 24
  • 55
  • I'm still not convinced that a factory class is necessary. Zend_Loader::loadClass takes a second parameter for directories to search, in the given order, but I can't find any way to pass that information to the autoloader. – pfyon Sep 23 '10 at 14:45