开发者

Link file to a row in Doctrine

I want to link a physical file with a row in a table. My intention is to use database habilities to delete the files that are referenced in the table. For example:

$o = Doctrine::getTable('Document开发者_运维知识库')->find(12); $o->delete();

This code delete the row in the table, i want to delete an hipotetical file referenced in $o->file_location. I'm trying it with Events (preDelete, postDelete, preUpdate, postUpdate) but i can't make it works.


In your Document model i would add something like this:

class Document extends BaseDocument
{
    ...

    public function preDelete($event)
    {
        unlink($this->file_location);
    }

    ...
}

Also, Doctrine has the Doctrine_Search_Files class which indexes (directories of) files for searching. Maybe you can get some inspiration there?


can't you just unlink the file?

like this:

$o = Doctrine::getTable('Document')->find(12);
if(unlink($o->file_location))
{
    $o->delete();
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜