On Fri, Mar 19, 2010 at 2:17 AM, Mike A <mik...@hotmail.co.uk> wrote: > On 18 Mar 2010 at 19:02, Jake McGraw wrote: >> I'd like to use Zend_Loader_Autoloader::setZfPath() and the >> autoloaderZfPath application.ini directive to select a ZF version >> based on Environment, exactly as described here: >> >> >> http://framework.zend.com/manual/en/zend.loader.autoloader.html#zend.loader.autoloader.zf-version >> >> What the tutorial fails to cover is how does one introduce >> Zend/Loader/Autoloader.php into your executing code without knowing >> the desired ZF path/version before executing Zend_Application? It's a >> kind of chicken and egg problem. Also, I've noticed that if you don't >> use the same version of Zend/Loader/Autoloader.php as the one you >> define in your setZfPath, then you'll get a fatal error (duplicate >> class) as require_once('Zend/Loader.php') will execute because you're >> now operating in a different directory. The only way around this issue >> is to remove every instance of require_once from all ZF classes and >> rely on Zend_Loader_Autoloader for all file inclusions. >> >> So, my question is, how are we supposed to use >> Zend_Loader_Autoloader::setZfPath() and the autoloaderZf directives? > As it happens I have just written about this issue in a > book chapter under authorship. Not perfect, but try... > $libraries="/../libraries/"; > $zf_path="ZF"; > $zf_ver="1.10.2";
Ok, but your use of $zf_path and $zf_ver makes the whole autoloaderZfPath, autoloaderZfVersion application.ini directives moot, correct? What I don't understand is, how does one use Zend_Loader_Autoloader::setZfPath(), without first loading some components of the Zend Framework? What I've encountered is that, as soon as you include/instantiate Zend_Loader_Autoloader, you've sullied the namespace, require_once won't look in the same directory as the original version of ZF that you used to include the autoloader, therefore, any duplicate require_once's will cause duplicate class errors. So, my question still stands, how does one use Zend_Loader_Autoloader::setZfPath(), where the ZF path will be different from the one used to include the autoloader? > // Ensure 'libraries/' folder is on include_path > set_include_path(implode(PATH_SEPARATOR, array( > realpath(APPLICATION_PATH . > $libraries.$zf_path.'/'.$zf_ver.'/library/'), > get_include_path(), ))); > require_once 'Zend/Application.php'; > $application = new Zend_Application( > APPLICATION_ENV, > APPLICATION_PATH . '/config/config.ini' > ); > $autoloader = Zend_Loader_Autoloader::getInstance(); > $path=realpath(APPLICATION_PATH . $libraries.$zf_path); > $autoloader->setZfPath($path, $zf_ver); > My folder structure matches the one in the example except > that Zend framework ("$zf_path") sits one level below my > libraries because I have personalised libraries I also > want to access. > It's messy, with more lines of code than necessary in a > perfect world - read "perfect framework" ;) Also, > depending on the need to transport across OSs, it may be > desirable to use the PATH_SEPARATOR constant in place of > "/". It does, though, enable a single change of $zf_ver to > attach the appropriate ZF version. > HTH a little... > Mike A. >