Zend Framework存储修改类的方法?

I have a project that uses Zend Framework and Zend_Translate.

I had to alter the standard CSV Adapter to Zend_Translate slightly. Now I'm confronted with the question where to put this altered adapter.

By default, adapters are stored in

/Library/Zend/Translate/Adapter/Adaptername.php

This is where I've put the new adapter as well.

However, I wouldn't like to "pollute" the Zend library with my custom extensions: I would like to stay able to update ZF without having to worry about losing files; I want to remain able to use a centrally installed version of ZF; and the custom adapter is part of the project I'm working on, really.

Is there a Zend Framework way of dealing with this, or specifying an alternative loading location?

Language adapters are loaded using

$this->_adapter = new $adapter($data, $locale, $options); 

(Where $adapter will be Zend_Translate_Adapter_Adaptername)

so standard autoloading rules apply. Is there a simple way to tell the Zend Autoloader to look in a second location?

You can add it to the lib folder

/lib
 /Zend
  /Translate
   /Adapter
    /Csv.php
 /My
  /Translate
   /Adapter
    /Csv.php

Depending on how your autoloader is setup, you have to setup the "namespace" with it:

$autoloader->registerNamespace('My_');

Or, if you dont like this, put it into your models folder. Basically, it doesnt matter where you put it, as long as it is accessible somehow by the autoloader. The Zend_Autoloader can register arbitrary autoloader callbacks, so it's really up to you.

I can't comment on Gordon's answer due to this site's rules, but he's got it right. To answer your question regarding how to load the adapter, you'll need to pass the full class name to the constructor of the translate object:

$translate = new Zend_Translate('My_Translate_Adapter_Class', ...);

The component first checks in the Zend namespace in case you've passed in a short name (like 'gettext'), but will then attempt to load the adapter name as a class directly.

At least, this is true in 1.10, and I imagine has been for a while.