开发者

Accessing the database and sending an email in a symfony batch script

I am running Symfony 1.3.2 on Ubuntu. I need to write a batch script that can:

  • Access the database using the ORM
  • Send email(s)

IIRC, this was in a previous cookback, but I thing that was for an earlier version of Symfony (the API may have changed since).

Does anyone know how I may access the database via the ORM layer in a batch script and also how to send out开发者_高级运维 email(s) in a batch script?


See also Sending email from a task in the "More with symfony" book.

If you get your task working, you can run it from cron or the command line.


Yep, put this at the top of your script:

require_once('/... ABSOLUTE_PATH...../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
sfContext::createInstance($configuration);

... and change the ABSOLUTE_PATH to the absolute path to the ProjectConguration class. Works for a batch script and allows use of ORM. Haven't tested with the standard Symfony SwiftMailer but assume would be fine.

The settings "frontend" and "prod" and "false" and app/environment-specific. You can read more about them in the Symfony API documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜