Difference between #2 and #3 of
How to use YiiBooster TbFileUpload widget

Revision #3 has been created by Antonio Ramirez on Dec 10, 2012, 7:52:35 AM with the memo:

Added 'Don Felipe' Notes
« previous (#2)


Title unchanged

How to use YiiBooster TbFileUpload widget

Category unchanged


Yii version unchanged

Tags unchanged

YiiBooster, How to, File upload

Content changed

I normally create a `files` folder and I allocate it within my `www` one, that is where I keep my css, js, images files. So, even though you can place it where ever you wish and for the sake of the example, I will use the `files` folder name.

I also assume that you have configured a path alias that references the `files` folder. On this example, the path alias is `frontend.www.files`.

### Note   
* This demo only works if the MyModel class already includes the function getImageUrl($img_type=null). If not, comment the 2 lines inside the data array, where 'url' and 'thumbnail_url' are defined, to make the demo work  
* If the MyModel has a different name, it needs to be replaced 1-2 times inside the upload action  
* The url where we are going to upload our files => upload action  
_Thanks [Don Felipe](http://www.yiiframework.com/user/9450/)_  
### Setup your model
The way you handle validation on the server is up to you, the configuration I am going to provide now is just an example.
$model = new MyModel('upload');
$model->picture = CUploadedFile::getInstance($model, 'picture');
if ($model->picture !== null && $model->validate(array('picture'))
Final Notes
The upload action example was not really tested, if any of you had problems with it, please submit your changes to the [YiiBooster Forum Topic](http://www.yiiframework.com/forum/index.php/topic/36258-yiibooster/). Any help would be highly appreciated to improve this wiki.

7 0
Viewed: 46 851 times
Version: 1.1
Category: How-tos
Written by: Antonio Ramirez
Last updated by: Antonio Ramirez
Created on: Dec 9, 2012
Last updated: 5 years ago
Update Article


View all history