将外部脚本与Zend Framework集成 [英] Integrating external scripts with Zend Framework

查看:85
本文介绍了将外部脚本与Zend Framework集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将外部脚本集成到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:

  • 如果扩展现有的ZF类,请复制ZF文件夹结构,以便文件具有相同的路径和名称(库名称除外).例如. /library/Zend/Db/Abstract.php =>/library/Project/Db/Abstract.php.
  • 如果您编写自己的类,请仍然遵循ZF命名约定以使自动加载器找到它们.

这篇关于将外部脚本与Zend Framework集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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