开发者

Cakephp Media Plugin Attachments Table

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('Attach开发者_如何学编程ment.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?


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜