I going use zend framework but just some tool of zend like translate, date and cache. Can I use it as standalone class? My project has it own structure and I don't want use the whole zend fw. If yes, which files should I include in my project? Is there a docs for using each zend fw tool as standalone?
views:
59answers:
2As an answer i could say Yes of course.
for example if u want to use Zend_Translate copy Translate.php and Translate folder to your library directory.
some times inside a class some other classes have been used. u have to copy them too. i find them by reading raised errors. ;)
And remember, to use various Zend Framework components in another project, you just need to have the Zend
library somewhere on your include_path
. Copying the whole thing may seem overkill to use one component, but it's only disk space. Having those files there doesn't affect performance unless they are called upon. And this way, you don't have to sweat the dependencies, like Zend_Exception
and its various component-specific subclasses.
So, for example, if you have a folder myapp/lib
to contain your external libraries, you simply make sure that your include path contains that lib
folder and copy the Zend
folder into it as myapp/lib/Zend
.
Then to use a component like Zend_Translate
, all you have to do is something like the following:
require_once 'Zend/Translate.php';
$options = array(
// your options here
);
$translate = new Zend_Translate($options);
With some kind of autloading mechanism in place, you can avoid even the require_once
call. Setting up autoloading is as easy as putting the following in some kind of common/bootstrap file:
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
Then any classes that follow the PEAR 1-class-1-file naming convention can be loaded without explicitly adding any require/include statements.
If disk-space really is a concern and you really don't want the whole Zend
library, then you could investigate a packageizer, like Jani Hartikainen's Packageizer.