将外部脚本集成到Zend Framework的最佳方法是什么? 让我解释一下,因为我可能会以错误的方式问这个问题。 我有一个下载和解析XML文件的脚本。 此脚本作为每日cron作业运行,需要将其数据转储到数据库中。
我在使用此脚本的站点上使用Zend Framework,在我看来,最好使用我的Zend_Db_Abstract子类模型来添加和更新数据库。 怎么去做这个? 我的脚本是否在Zend Components旁边的库中(即library / Mine / Xmlparse.php),因此可以访问各种ZF组件? 我只需要在文件本身中包含正确的模型文件和Zend DB组件吗? 处理这种集成的最佳方法是什么?
What is the best way to integrate an external script into the Zend Framework? Let me explain because I may be asking this the wrong way. I have a script that downloads and parses an XML file. This script, which runs as a daily cron job, needs to dump its data into the database.
I am using Zend Framework for the site which uses this script and it seems to me that it would be best to use my subclassed model of Zend_Db_Abstract to do the adding and updating of the database. How does one go about doing this? Does my script go in the library next to the Zend Components (i.e. library/Mine/Xmlparse.php) and thus have access to the various ZF components? Do I simply need to include the correct model files and the Zend DB component in the file itself? What is the best way to handle this sort of integration?
最满意答案
在库目录中,您应该在Zend库文件夹旁边拥有自己的库。 无论你怎么称呼它(Mylib,Project,......)你都应该将它包含在Zend Autoloader中,并按如下方式完成:
require_once 'Zend/Loader/Autoloader.php'; $loader = Zend_Loader_Autoloader::getInstance(); $loader->registerNamespace('Project_'); $loader->setFallbackAutoloader(true); if ($configSection == 'development') { $loader->suppressNotFoundWarnings(false); }为了让您的库与ZF和Autoloader很好地集成,您应该遵循ZF命名约定。 这意味着两件事:
如果扩展现有ZF类,请复制ZF文件夹结构,以使文件具有相同的路径和名称,但库名称除外。 例如/library/Zend/Db/Abstract.php => /library/Project/Db/Abstract.php。 如果您编写自己的类,仍然坚持自动加载器的ZF命名约定来查找它们。In your library directory you should have your own library next to the Zend library folder. Whatever you call it (Mylib, Project, ...) you should include it into the Zend Autoloader and that's done as follows:
require_once 'Zend/Loader/Autoloader.php'; $loader = Zend_Loader_Autoloader::getInstance(); $loader->registerNamespace('Project_'); $loader->setFallbackAutoloader(true); if ($configSection == 'development') { $loader->suppressNotFoundWarnings(false); }In order for you library to integrate nicely with ZF and the Autoloader you should stick to the ZF naming conventions. This means two things:
if you extend an existing ZF class, replicate the ZF folder structure so that your file has the same path and name except for the library name. E.g. /library/Zend/Db/Abstract.php => /library/Project/Db/Abstract.php. if you write your own classes, still stick to the ZF naming conventions for the autoloader to find them.更多推荐
发布评论