0

I've got the following model class:

class ContractDetails extends BaseContractDetails {

    public function updateContractDetailsByConId($conId, $key, $value) {
        $q = Doctrine_Query::create()
              ->update('ContractDetails');
        if ($value === null) {
            $q->set($key, 'NULL');
        } else {
            $q->set($key, '?', $value);
        }

        $q->where('cd_con_id = ?', $conId)
                ->execute();

        return $q;
    }
    public function preUpdate($values) {
        $test = "test";
    }
 }

What I want is to run some code before the "updateContractDetailsByConId" method row is updated. From my investigations I should be able to use the built in hooks i.e. preUpdate But the preUpdate method is never running.

Any ideas why not?

4

1 回答 1

2

当您从 DQL 查询更新时,您需要挂钩到 DQL 回调。有关更多信息,请参阅此处的文档。

在您的代码中,您需要更新preUpdatefor

public function preDqlUpdate($values) {
   $test = "test";
}

不要忘记,如文档中所述,您需要隐式打开 DQL 回调。在您的 ProjectConfiguration.class.php 文件中,添加:

public function configureDoctrine(Doctrine_Manager $manager)
{
   $manager->setAttribute(Doctrine::ATTR_USE_DQL_CALLBACKS, true);
}
于 2013-03-14T12:59:11.173 回答