Hi,
I’m in a bit of a pickle here and hope get help.
The Senario:
I have a multiple product attributes, each has an image associated to it. In submitted product attributes, I segregate the by models to update, models to delete, models to insert.
As a result, I will need to move file upload to the same Active Record Model as well.
Product attributes model is called "ProdAttributes" <- extends active record.
Product attribute images model is called "Upload" <- extends model.
For product attributes to be inserted I added the following code in "ProdAttributes" to handle uploaded images.
$uploader = new Upload();
$uploader->image = Uploader::getInstance($uploader, 'image');
if($uploader->upload($prod_attribute_id)) {
echo 'Uploaded';die;
}
In Upload model I have the following code:
public function rules() {
return [['image', 'image', 'skipOnEmpty' => false, 'extensions' => 'png, jpg, jpeg']];
}
public function upload($prod_attribute_id) {
if ( $this->validate() ) {
...
$this->image->saveAs();
...
}
}
The Error:
The validation always fails with message "Please upload a file".
The Investigation:
With that error I investigated the follow:
"$uploader->image" contains the image upload object (Sounds good)
When I "var_dump($this)" of "$this->validate()" defined in Upload model returns the attributes defined in the active record of "ProdAttributes" (Not Good). It expected to return only the "image" attribute defined in Upload model.
Any idea on how to get past this?
Thanks,