将外部脚本集成到 Zend 框架的最佳方法是什么?让我解释一下,因为我可能问错了.我有一个下载和解析 XML 文件的脚本.该脚本作为日常 cron 作业运行,需要将其数据转储到数据库中.
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.
我正在为使用此脚本的站点使用 Zend Framework,在我看来,最好使用我的 Zend_Db_Abstract
子类模型来添加和更新数据库.怎么做呢?我的脚本是否位于 Zend 组件旁边的库中(即 library/Mine/Xmlparse.php),从而可以访问各种 ZF 组件?我是否只需要在文件本身中包含正确的模型文件和 Zend DB 组件?处理这种集成的最佳方法是什么?
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 中,具体操作如下:
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);
}
为了让您的库与 ZF 和 Autoloader 很好地集成,您应该坚持 ZF 命名约定.这意味着两件事:
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:
这篇关于将外部脚本与 Zend Framework 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!