我可以在我的项目中使用 Zend translate、date 和 cache 作为独立类吗?
我将使用 Zend 框架,但只是 Zend 的一些工具,如翻译、日期和缓存.我可以将它用作独立类吗?我的项目有自己的结构,我不想使用整个 Zend 固件.如果是,我应该在我的项目中包含哪些文件?是否有单独使用每个 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 组件,您只需要在您的 Zend
库的某个位置>include_path.使用一个组件复制整个内容似乎有些矫枉过正,但这只是磁盘空间.除非调用它们,否则将这些文件放在那里不会影响性能.这样,您就不必担心依赖项,例如 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
调用.设置自动加载就像将以下内容放在某种通用/引导文件中一样简单:
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.
相关文章