Cakephp 媒体插件附件表

发布于 2024-12-04 16:02:29 字数 1306 浏览 1 评论 0原文

我想使用 cakephp 媒体插件(https://github.com/davidpersson/media by David Persson)上传文件并将其附加到多个模型。

附件属于模型 A、模型 B 等。

模型 A 具有许多附件

模型 B 具有许多附件

为了使 Media.Coupler 正常工作,文档称需要将“basename”和“dirname”字段添加到模型中。当我向 posts 表添加基本名称和目录名称时,我可以让插件正常工作。

帖子模型的设置是:

// Attachments
var $hasMany = array( 'Attachment' => array( 
        'className' => 'Media.Attachment', 
        'foreignKey' => 'foreign_key', 
        'conditions'    => array('Attachment.model' => 'Post', 'Attachment.group' => 'post'),
        'dependent' => true, 
    ) 
); 

public $actsAs = array(
    'Media.Transfer',
    'Media.Generator',
    'Media.Coupler',    
);  

我注意到安装并初始化插件后,数据库有一个名为附件的新表,可用于此目的,但没有数据保存到其中???

CREATE TABLE `attachments` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`model` varchar(255) NOT NULL,
`foreign_key` int(10) NOT NULL,
`dirname` varchar(255) DEFAULT NULL,
`basename` varchar(255) NOT NULL,
`checksum` varchar(255) NOT NULL,
`group` varchar(255) DEFAULT NULL,
`alternative` varchar(50) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM; 

我不想向所有需要附件的模型添加基本名称和目录名称。

是否可以配置媒体插件以将上传保存到附件表并通过模型+外键链接它们?

有人成功使用媒体插件和这种设置吗?

I would like to use the cakephp media plugin (https://github.com/davidpersson/media by David Persson) to upload files and attach them to multiple models.

Attachment BelongsTo Model A, Model B etc.

Model A HasMany Attachments

Model B HasMany Attachments

In order for the Media.Coupler to work the documentation says a "basename" and "dirname" field needs to be added to the model. I can get the plugin to work when I add a basename and dirname to posts table.

The setup of the post model is:

// Attachments
var $hasMany = array( 'Attachment' => array( 
        'className' => 'Media.Attachment', 
        'foreignKey' => 'foreign_key', 
        'conditions'    => array('Attachment.model' => 'Post', 'Attachment.group' => 'post'),
        'dependent' => true, 
    ) 
); 

public $actsAs = array(
    'Media.Transfer',
    'Media.Generator',
    'Media.Coupler',    
);  

I noticed that after installing and initing the plugin the database has a new table called attachments which could be used for this but no data is saved to it???

CREATE TABLE `attachments` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`model` varchar(255) NOT NULL,
`foreign_key` int(10) NOT NULL,
`dirname` varchar(255) DEFAULT NULL,
`basename` varchar(255) NOT NULL,
`checksum` varchar(255) NOT NULL,
`group` varchar(255) DEFAULT NULL,
`alternative` varchar(50) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM; 

I would rather not add a basename and dirname to all my models that need attachments.

Is it possbile to configure the media plugin to save uploads to the attachments table and link them via the model + foreign_key?

Has anyone succeeded with the media plugin and this kind of setup?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

草莓酥 2024-12-11 16:02:29

我的情况和你类似,几乎没有什么区别:

· 模型 A HasOne 附件

· 模型 B HasOne 附件

· 我正在尝试使用 jquery Fileuploader 插件遵循本教程

好吧,我想你的答案问题是是的,在用这个插件打破我的头之后...您可以避免将基本名称和目录名称添加到您的 A 或 B 模型中,只是不要使用耦合器。我认为这是它唯一的功能,尽管我不确定......它只给我带来了我确定的问题。

我所做的是在创建帖子时手动将模型和foreign_key字段添加到附件模型中。

如果您需要更多信息,我可以给您我的电子邮件,

干杯

I'm at a similar situation as you, with little difference:

· Model A HasOne Attachments

· Model B HasOne Attachments

· And i'm trying to use the jquery Fileuploader plugin following this tutorial

Well, I think the answer to your question is YES, after breaking my head with this plugin... You can avoid adding basename and dirname to your A or B model, just don't use the coupler. I think that is its only function, although i'm not sure... it only gave me problems of that i'm sure.

What i do is manually add the model and foreign_key fields to the attachment model as I create a Post.

If you need more info i can give you my e-mail,

cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文