background image

 

此文件的其余部分将包含需要执行的简单任务。包括并实例化 posts 模型,创

建 where 

 

子句并运行标准的 delete 查询。

 

清单 2. 要执行的任务

                

requ i re_once( " / co lumn/p ro tec ted /zend /mode ls /Pos ts .php" ) ;

$pos ts  =  new  Pos ts ( ) ;

$where  =  $pos ts - >getAdapter ( ) - >quote In to ( 'mod i f i ed    <  ? ' ,  

    date ( ' Y- m-d  H: i : s ' ,   s t r to t ime( ' - 30  days ' ) ) ) ;

$pos ts - >de le te ($where ) ;

?>

这 一 切 完 成 后 , 您 可 以 在 命 令 行 中 执 行 这 个 脚 本 : php 

/column/protected/zend/scripts/prune.php。

 

如果可以从命令行调用脚本,则可以对脚本进行调度、批处理或 cron。要在午夜执行

此 脚 本 的  crontab 条 目 可 能 类 似 这 段 代 码 : 00   00   *   *   *   php 

/column/protected/zend/scripts/prune.php。

 

在构建了脚本控制器后,您有许多选项可用于通过 Zend 框架执行脚本。您可以使用

在应用程序的其余部分中使用的相同模型,在必要时创建复杂的脚本对象等等。

 

现在您已经很好地掌握了如何为 Zend 

 

执行 cron 作业。接下来,让我们看看如何在 

symfony 中执行相同操作。

symfony 中的外部任务

 

当需要在 Zend 框架中执行命令行脚本时,您创建了可用于替代前端控制器的脚本

 

控制器。您将对 symfony 执行类似的操作。