this is one of my very first posts. I’ve made great use of the forum to learn the basics, I now have a problem I can’t understand and can’t solve, so some help would be appreciated.
I have an action that accepts the upload of an image file, along with a few other model fields. It works fine if I upload a file, but if the (non-required) image field is not filled out, I get an error:
Trying to get property of non-object
This occurs where I try to use the uploaded file extension in forming the new filename:
Thanks for the feedback - yes I’ve been testing without validation, and its not really the solution.
My Labels model rules are:
public function rules()
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
array('winery_id, name', 'required'),
array('rating_5, price_range_id, retail_category_id', 'numerical', 'integerOnly'=>true),
array('winery_id', 'length', 'max'=>11),
array('name', 'length', 'max'=>80),
array('image', 'file', 'types'=>'jpg, gif, png'),
array('thumbnail', 'length', 'max'=>50),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, winery_id, sub_label, name, rating_5, image, thumbnail, price_range_id, retail_category_id', 'safe', 'on'=>'search'),
So as far as I can see there’s no need to have an image.
OK ! that nailed it. Thanks a million. I also had to change the order of testing with the saving/redirecting. When there was no file it failed with the old setup of testing both the save and the file together.