Hi,
I have been using Yii for a couple of projects now. The API is very clear in most places, but not about files. I have fundamental doubt.
What does it mean to declare a field as a
file
? The API says it represents only uploaded files. Now if I view the table in question through (say) phpmyadmin, I see only the filename goes into the path.
Here is my table schema
Name Type Collation Attributes Null Default Extra
1 ID int(11) No None AUTO_INCREMENT
2 productID int(11) No None
3 path text utf8_unicode_ci No None
here is my model code
public function rules() {
return array(
array('productID, path', 'required'),
array('productID', 'numerical', 'integerOnly'=>true),
array('productID', 'safe', 'on'=>'search'),
array('path','file','types'=>'jpg, gif, png','allowEmpty'=>false),
);
}
So even though the table stores text, the file object holds more (more on this next post). I can’t save the object properly if I manually assign the file name like :
$image = CUploadedFile::getInstance($model,'ProductPhoto');
$this->path=$image->name;
I must assign it like :
$image = CUploadedFile::getInstance($model,'ProductPhoto');
$this->path=$image;
even though phpMyAdmin reports :
ID | productID | path
1 | 2 | Hydrangeas.jpg
Can someone throw more light on this please?
Milind