Hey, thanks Jonah!! that’d handle the “1 file” requirement, but what approach do you suggest for the more generic one model with as many files as you want? (user could restrict to a number)
Yesterday I took the challenge of writing a few lines that I’ll try to publish in a near future but here are an advance:
I told yesterday I wanted to take out of the "extension user" as much code as I can, so that all can be more "automatic", I created an extension with:
-
a File model, that autocreates and manages file table
-
a generic abstract UploadWidget following Strategy pattern, to be extended by concrete strategies (I started by SimpleUpload using a simple filefield, and I’ll follow with SwfUpload that I implemented a couple of months ago with very good result)
-
a generic UploadBehaviour, extended by the concrete implementations
With this, in my "user code", providing I created one custom model with yiishell, I had to:
- configurate (just by comfort) the config file main.php with:
'ext.upload.*',
'ext.upload.simple.*',
public function relations() {
return array(
'files'=>array(self::HAS_MANY, 'File', 'EXid', 'condition'=>"entity='".get_class($this)."'"),
);
}
public function behaviors() {
return array(
'UploadBehaviour' => array('class' => 'application.extensions.upload.simple.SimpleUploadBehaviour',)
);
}
- add to the view form of the model:
<div class="row">
<?php $this->widget("SimpleUploadWidget", array(
'files' => $model->files,
)); ?>
</div>
- I’d have to append to customController the actions provided by the widget (for advanced usage to show filePanel, deletion of files, etc.
… and for the basic example, it’s working, in your code you just have to worry about displaying files in the way you want using $myCustomModel->files (I have to think about but maybe the extension should provide with a few views to make this even easier…)
I’d like to make it work as a proof of concept to write more extensions with this approach, as I told I use to write modules for drupal, and the next I have in mind is a categorization extension
Thank you guys… I’ll keep you informed
Hwangar