Excellent! Now we have a widget wich works exactly how worked CHtml::activeFileField(), we can move forward for use uploadify
Import uploadifyThe first instruction (assetsManger->publish) publish the directory and return the path created.
The other options publish the script and css file. Please note that we include the yii version of jquery (), not the uploadify one for avoid conflicts.
### Register the script
Our objective is to register this script:
```php
<script type="text/javascript">
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '/uploadify/uploadify.php',
'cancelImg' : '/uploadify/cancel.png',
'folder' : '/uploads',
'auto' : true
});
});
</script>
```
And to reserve us the possiblity of customize it.
Let's add a property options:
```php
public $options;
```
And then we prepare the options like that:
```php
$options= CJavaScript::encode(array_merge(
array(
'uploader' => $assetsFolder.'/uploadify.swf',
'script' => $assetsFolder.'/uploadify.php',
'cancelImg' => $assetsFolder.'/cancel.png',
'folder' => '/uploads',
'auto' => true
),
$this->options
));
```
The options are made up by some standard options (uploader, script , cancelImg, folder and auto) that will be merged with the user defined options.
User defined options will take precedence (they are the second array in array_merge), so we will have the possiblity of override the default ones.
This options will be encoded with Cjavascript::encode(), a magic function that allow to give javascript functions as parameters, we have just to write 'js:' at the begining.
For register the script we need only the id, we can generate the id with CHtml, respecting any chouce of the user:
For any customization, follow the documentation of uploadify. The work of Yii framework was only to give a structure in wich easy inlcude all needed file.