//PHP files steps
Now with the provided data types of our mysql table the Gii CRUD generator will create a form that has text fields and text areas. However I did not want to manually specify any of these fields in stead I wanted to populate these values depending on the image being uploaded.
The first thing to do is to add a variable to our model class file. In my case is under protected/models/PropertyPicture.php
public $imageFile;
This variable has to be added so that we can access the image after being uploaded on the form provided by the CRUD object.
Then we modify the rules() method so that our imageFile is required and it is recognized as an image.
NOTE: I removed imageName(text), imagePath(text), imageType(text) from the required array since these values will be populated after uploading the image file and the user does not manually enter these values. If you happen to remove the validation rules for these fields before modifying the form file then the whenever you create a new picture or modify an existing one these values will not be passed from the form to the database.
This is how my rules method looks like:
public function rules()
{
return array(
array('propertyID, imageFile', 'required'),
array('imageFile','unsafe'),
array('imageFile','file','types'=>'jpg, gif, png'),
array('propertyID', 'numerical', 'integerOnly'=>true),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('imageID, propertyID, imageName, imagePath, imageType', 'safe', 'on'=>'search'),
);
}
I am not entirely sure why you have to set imageFile as unsafe but I read it somewhere in the forum.
Finally add an entry for the attributeLabels function like this:
'imageFile' => 'Image File'
NOTE: I cannot post the rest of the steps since I’m a noob 