問題描述
我將使用 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.
這篇關于我可以在我的項目中使用 Zend translate、date 和 cache 作為獨立類嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!