我想让Symfony将我的一项任务执行的Doctrine SQL查询记录到日志文件中,就像web调试工具栏为非cli代码所做的那样。这可能吗?从Symfony 1.4任务记录原则查询
- Symfony的版本:1.4.12
- 学说版本:1.2.4
下面是任务的一些示例代码。我希望以类似的方式记录SELECT查询,如果它是从操作中调用的话。
class exampleTask extends sfBaseTask
{
protected function configure()
{
parent::configure();
$this->namespace = 'test';
$this->name = 'example';
}
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$users = Doctrine_Core::getTable('SfGuardUser')
->createQuery('s')
->select('s.first_name')
->execute();
foreach($users as $user) {
print $user->getFirstName()."\n";
}
}
}
任务不是应用程序的一部分 - 似乎没有包含任务的settings.yml。 –
@伊格雷戈里:对不起,如果我的答案目前没有那么有用。你能否指定你正在使用的学说版本和你的任务,它的代码在答案中? – hakre