我可以在项目中使用zend转换,日期和缓存作为独立类吗? [英] Can I use zend translate, date and cache as standalone class in my project?

查看:70
本文介绍了我可以在项目中使用zend转换,日期和缓存作为独立类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用Zend框架,但仅使用Zend的某些工具,例如翻译,日期和缓存.我可以将其用作独立类吗?我的项目有其自己的结构,所以我不想使用整个Zend fw.如果是,我应该在项目中包括哪些文件?是否有文档可单独使用每个Zend fw工具?

I'm going to 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?

推荐答案

请记住,要在另一个项目中使用各种Zend Framework组件,您只需要在include_path上的某个地方放置Zend库.复制整个内容似乎对于使用一个组件来说是过大的杀伤力,但这只是磁盘空间.除非调用这些文件,否则这些文件不会影响性能.这样,您就不必像Zend_Exception及其各种特定于组件的子类那样依赖这些依赖项.

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.

因此,例如,如果您有一个文件夹myapp/lib来包含您的外部库,则只需确保您的包含路径包含该lib文件夹,然后将Zend文件夹复制为myapp/lib/Zend到其中即可.

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.

然后使用像Zend_Translate这样的组件,您要做的只是以下内容:

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);

有了适当的自动加载机制,您甚至可以避免require_once调用.设置自动加载就像将以下内容放入某种common/bootstrap文件一样简单:

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();

然后遵循 PEAR 1-class-1-file命名约定的所有类可以加载而无需显式添加任何require/include语句.

Then any classes that follow the PEAR 1-class-1-file naming convention can be loaded without explicitly adding any require/include statements.

如果确实需要磁盘空间,并且您真的不想要整个Zend库,则可以研究一个打包程序,例如 Jani Hartikainen的打包器.

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.

这篇关于我可以在项目中使用zend转换,日期和缓存作为独立类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆